]> git.cworth.org Git - turbot/commitdiff
Rename primary-key attribute from PK to hunt_id
authorCarl Worth <cworth@cworth.org>
Thu, 31 Dec 2020 20:05:13 +0000 (12:05 -0800)
committerCarl Worth <cworth@cworth.org>
Thu, 31 Dec 2020 20:05:13 +0000 (12:05 -0800)
I was just about to add a separate attribut to every item in the
database named hunt_id when I realized that that was totally redundant
with our existing PK attribute (whose values were simply the hunt_id
prefixed by "hunt-" in all cases).

Since we're not using the PK field in any generalized sense, (that is,
it's _always_ populated with the hunt_id value), it's much simpler and
more efficient to just name it "hunt_id" and store the hunt_id valeu
ther directly (without any prefix).

turbot/events.py
turbot/interaction.py

index 3b04036f8aafca480b2988ffc76a13c8629ebab5..267d9397a6e2ee6d9336d967bf09561c9e0ca158 100644 (file)
@@ -60,7 +60,7 @@ def hunt_block(turb, hunt):
 
     response = turb.table.query(
         KeyConditionExpression=(
-            Key('PK').eq('hunt-{}'.format(hunt_id)) &
+            Key('hunt_id').eq(hunt_id) &
             Key('SK').begins_with('puzzle-')
         )
     )
index 06181887beb3f1c6632dda3f21607c88aa5e6b9c..31d554942f580d11566ddfb9b91b15122e865c5a 100644 (file)
@@ -108,11 +108,11 @@ def new_hunt_submission(turb, payload, metadata):
         turb.table = turb.db.create_table(
             TableName='turbot',
             KeySchema=[
-                {'AttributeName': 'PK', 'KeyType': 'HASH'},
+                {'AttributeName': 'hunt_id', 'KeyType': 'HASH'},
                 {'AttributeName': 'SK', 'KeyType': 'RANGE'},
             ],
             AttributeDefinitions=[
-                {'AttributeName': 'PK', 'AttributeType': 'S'},
+                {'AttributeName': 'hunt_id', 'AttributeType': 'S'},
                 {'AttributeName': 'SK', 'AttributeType': 'S'},
                 {'AttributeName': 'channel_id', 'AttributeType': 'S'},
                 {'AttributeName': 'is_hunt', 'AttributeType': 'S'},
@@ -168,10 +168,9 @@ def new_hunt_submission(turb, payload, metadata):
     # (leaving it as non-active for now until the channel-created handler
     #  finishes fixing it up with a sheet and a companion table)
     item={
-        "PK": "hunt-{}".format(hunt_id),
+        "hunt_id": hunt_id,
         "SK": "hunt-{}".format(hunt_id),
         "is_hunt": hunt_id,
-        "hunt_id": hunt_id,
         "channel_id": channel_id,
         "active": False,
         "name": name,
@@ -297,7 +296,7 @@ def find_hunt_for_hunt_id(turb, hunt_id):
     """
     turbot_table = turb.db.Table("turbot")
 
-    response = turbot_table.get_item(Key={'PK': 'hunt-{}'.format(hunt_id)})
+    response = turbot_table.get_item(Key={'hunt_id': hunt_id})
 
     if 'Item' in response:
         return response['Item']
@@ -402,7 +401,7 @@ def puzzle_submission(turb, payload, metadata):
 
     # Insert the newly-created puzzle into the database
     item={
-        "PK": "hunt-{}".format(hunt_id),
+        "hunt_id": hunt_id,
         "SK": "puzzle-{}".format(puzzle_id),
         "puzzle_id": puzzle_id,
         "channel_id": channel_id,