From 83cb7e7717f1407ecc525bcc290489b7ce2480b0 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Thu, 31 Dec 2020 11:52:43 -0800 Subject: [PATCH] Rename hunt_id_index to is_hunt_index Backed, of course, by a new is_hunt attribute. The rationale here is that the whole point of this index is to be a sparse attribute so that the code can efficiently query all existing hunts. But meanwhile, it's useful for puzzles to have a "hunt_id" attribute, which would confict with the goal of having "hunt_id" be sparse and populated only for hunts and not puzzles. So the fix here is to make hunt_id universal, and instead have a separate "is_hunt" attribute which is the sparse one, (and will clearly never be populated for a puzzle). --- turbot/events.py | 2 +- turbot/interaction.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/turbot/events.py b/turbot/events.py index d701994..3b04036 100644 --- a/turbot/events.py +++ b/turbot/events.py @@ -83,7 +83,7 @@ def home(turb, user_id): # Behave cleanly if there is no "turbot" table at all yet. try: response = turb.table.scan( - IndexName="hunt_id_index", + IndexName="is_hunt_index", ) hunts = response['Items'] except Exception: diff --git a/turbot/interaction.py b/turbot/interaction.py index bb4b868..0618188 100644 --- a/turbot/interaction.py +++ b/turbot/interaction.py @@ -115,7 +115,7 @@ def new_hunt_submission(turb, payload, metadata): {'AttributeName': 'PK', 'AttributeType': 'S'}, {'AttributeName': 'SK', 'AttributeType': 'S'}, {'AttributeName': 'channel_id', 'AttributeType': 'S'}, - {'AttributeName': 'hunt_id', 'AttributeType': 'S'}, + {'AttributeName': 'is_hunt', 'AttributeType': 'S'}, ], ProvisionedThroughput={ 'ReadCapacityUnits': 5, @@ -136,9 +136,9 @@ def new_hunt_submission(turb, payload, metadata): } }, { - 'IndexName': 'hunt_id_index', + 'IndexName': 'is_hunt_index', 'KeySchema': [ - {'AttributeName': 'hunt_id', 'KeyType': 'HASH'} + {'AttributeName': 'is_hunt', 'KeyType': 'HASH'} ], 'Projection': { 'ProjectionType': 'ALL' @@ -170,6 +170,7 @@ def new_hunt_submission(turb, payload, metadata): item={ "PK": "hunt-{}".format(hunt_id), "SK": "hunt-{}".format(hunt_id), + "is_hunt": hunt_id, "hunt_id": hunt_id, "channel_id": channel_id, "active": False, -- 2.43.0