From 9618e66b093ec89efbdbeae6a2efa159cd513b33 Mon Sep 17 00:00:00 2001 From: naathanbrown Date: Thu, 21 Mar 2024 10:50:33 +0000 Subject: [PATCH 1/3] feat(cb2-11440): filter out already TTL'd items --- src/dynamo/getDynamoRecords.ts | 2 ++ src/handler.ts | 2 +- tests/unit/getDynamoRecords.test.ts | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/dynamo/getDynamoRecords.ts b/src/dynamo/getDynamoRecords.ts index 2ed1a14..7b8abd4 100644 --- a/src/dynamo/getDynamoRecords.ts +++ b/src/dynamo/getDynamoRecords.ts @@ -9,8 +9,10 @@ export const getDynamoMembers: () => Promise = async () => { .query({ TableName: config.aws.dynamoTable, KeyConditionExpression: 'resourceType = :type', + FilterExpression: 'attribute_not_exists(ttl) or ttl = :null', ExpressionAttributeValues: { ':type': ResourceType.User, + ':null': null, }, } as AWS.DynamoDB.DocumentClient.QueryInput) .promise(); diff --git a/src/handler.ts b/src/handler.ts index e062692..9004119 100644 --- a/src/handler.ts +++ b/src/handler.ts @@ -54,7 +54,7 @@ function generateStatements( const SECONDS_IN_AN_HOUR = 60 * 60; const HOURS_IN_A_DAY = 24; const secondsSinceEpoch = Math.round(Date.now() / 1000); - const expirationTime = (secondsSinceEpoch + HOURS_IN_A_DAY * SECONDS_IN_AN_HOUR) - SECONDS_IN_AN_HOUR; + const expirationTime = secondsSinceEpoch + HOURS_IN_A_DAY * SECONDS_IN_AN_HOUR - SECONDS_IN_AN_HOUR; const drMap = dynamoRecords .filter((dr) => !azureMembers.some((am) => am.id === dr.resourceKey)) diff --git a/tests/unit/getDynamoRecords.test.ts b/tests/unit/getDynamoRecords.test.ts index 0c56dc5..5a11d4e 100644 --- a/tests/unit/getDynamoRecords.test.ts +++ b/tests/unit/getDynamoRecords.test.ts @@ -53,8 +53,10 @@ describe('getDynamoMembers', () => { expect(mockDynamoQuery).toBeCalledWith({ TableName: 'testTable', KeyConditionExpression: 'resourceType = :type', + FilterExpression: 'attribute_not_exists(ttl) or ttl = :null', ExpressionAttributeValues: { ':type': ResourceType.User, + ':null': null, }, } as AWS.DynamoDB.DocumentClient.QueryInput); }); From 56673b9d1e904110ae07763032135a284ac9c04a Mon Sep 17 00:00:00 2001 From: naathanbrown Date: Thu, 21 Mar 2024 11:11:18 +0000 Subject: [PATCH 2/3] feat(cb2-11440): Dynamo is the worst thing ever --- src/dynamo/getDynamoRecords.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/dynamo/getDynamoRecords.ts b/src/dynamo/getDynamoRecords.ts index 7b8abd4..e1c8689 100644 --- a/src/dynamo/getDynamoRecords.ts +++ b/src/dynamo/getDynamoRecords.ts @@ -9,11 +9,14 @@ export const getDynamoMembers: () => Promise = async () => { .query({ TableName: config.aws.dynamoTable, KeyConditionExpression: 'resourceType = :type', - FilterExpression: 'attribute_not_exists(ttl) or ttl = :null', + FilterExpression: 'attribute_not_exists(#ttl_key) or #ttl_key = :null', ExpressionAttributeValues: { ':type': ResourceType.User, ':null': null, }, + ExpressionAttributeNames: { + '#ttl_key': 'ttl', + }, } as AWS.DynamoDB.DocumentClient.QueryInput) .promise(); From 73657f56d57846c3beb47b4e27391cc16b47c34e Mon Sep 17 00:00:00 2001 From: naathanbrown Date: Thu, 21 Mar 2024 11:12:45 +0000 Subject: [PATCH 3/3] feat(cb2-11440): Dynamo is the worst thing ever --- tests/unit/getDynamoRecords.test.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/unit/getDynamoRecords.test.ts b/tests/unit/getDynamoRecords.test.ts index 5a11d4e..99524e0 100644 --- a/tests/unit/getDynamoRecords.test.ts +++ b/tests/unit/getDynamoRecords.test.ts @@ -53,11 +53,14 @@ describe('getDynamoMembers', () => { expect(mockDynamoQuery).toBeCalledWith({ TableName: 'testTable', KeyConditionExpression: 'resourceType = :type', - FilterExpression: 'attribute_not_exists(ttl) or ttl = :null', + FilterExpression: 'attribute_not_exists(#ttl_key) or #ttl_key = :null', ExpressionAttributeValues: { ':type': ResourceType.User, ':null': null, }, + ExpressionAttributeNames: { + '#ttl_key': 'ttl', + }, } as AWS.DynamoDB.DocumentClient.QueryInput); }); });