Skip to content

Commit a651503

Browse files
committed
fix(hideBefore): only delete shadow if the date changes
1 parent 2f5e98d commit a651503

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

cdk/resources/DeviceStorage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class DeviceStorage extends Construct {
1818
? RemovalPolicy.DESTROY
1919
: RemovalPolicy.RETAIN,
2020
pointInTimeRecovery: true,
21-
stream: DynamoDB.StreamViewType.NEW_IMAGE,
21+
stream: DynamoDB.StreamViewType.NEW_AND_OLD_IMAGES,
2222
})
2323
this.devicesTable.addGlobalSecondaryIndex({
2424
indexName: this.devicesTableFingerprintIndexName,

cdk/resources/UpdateDevice.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export class UpdateDevice extends Construct {
7272
S: [{ exists: true }],
7373
},
7474
},
75+
OldImage: [{ exists: true }],
7576
},
7677
}),
7778
],

lambda/onHideData.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,26 @@ export const handler = middy()
1515
.handler(async (event: DynamoDBStreamEvent): Promise<void> => {
1616
for (const record of event.Records) {
1717
const newImage = record.dynamodb?.NewImage
18-
if (newImage === undefined) {
18+
const oldImage = record.dynamodb?.OldImage
19+
if (newImage === undefined || oldImage === undefined) {
1920
continue
2021
}
22+
const { hideDataBefore: oldHideDataBefore } = unmarshall(
23+
oldImage as Record<string, AttributeValue>,
24+
) as { hideDataBefore: string }
2125
const { deviceId, hideDataBefore } = unmarshall(
2226
newImage as Record<string, AttributeValue>,
2327
) as {
2428
deviceId: string
2529
hideDataBefore: string
2630
}
31+
32+
if (hideDataBefore === oldHideDataBefore) {
33+
console.log(
34+
`No change in hideDataBefore for device ${deviceId}, skipping...`,
35+
)
36+
continue
37+
}
2738
console.log(
2839
`Hiding data before ${hideDataBefore} for device ${deviceId}...`,
2940
)

0 commit comments

Comments
 (0)