From 81f6fdf3c28a4fe2a7638dd399d0fcd835a21c54 Mon Sep 17 00:00:00 2001 From: Andrea Vos Date: Fri, 3 Jan 2025 15:00:09 +0100 Subject: [PATCH] fix cleanupImages --- server/cleanupImages.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/server/cleanupImages.ts b/server/cleanupImages.ts index 668323b63..dc4ae4e91 100644 --- a/server/cleanupImages.ts +++ b/server/cleanupImages.ts @@ -14,7 +14,7 @@ const validateIds = (type: string, data: Record, expectedMinimu console.log(`${type}: ${Object.keys(data).length}`); if (Object.keys(data).length <= expectedMinimumSize) { - throw new Error('Unexpected empty list of ids to stay!'); + throw new Error('List of ids has unexpectedly few items!'); } const invalidKeys = []; @@ -111,11 +111,13 @@ async function cleanup(): Promise { let fresh = 0; let removed = 0; let removedSize = 0; + let awsRequests = 0; const chunkSize = 1000; let continuationToken: string | undefined = undefined; while (true) { console.log('Making a request'); + awsRequests++; const objects: ListObjectsV2Output = await s3.listObjectsV2({ Prefix: 'images/', MaxKeys: chunkSize, @@ -168,6 +170,7 @@ async function cleanup(): Promise { if (execute && toRemove.length) { console.log('--- Removal request ---'); + awsRequests++; await s3.deleteObjects({ Delete: { Objects: toRemove, @@ -185,6 +188,7 @@ async function cleanup(): Promise { continuationToken = undefined; while (true) { console.log('Making a request'); + awsRequests++; const objects: ListObjectsV2Output = await s3.listObjectsV2({ Prefix: 'card/', MaxKeys: chunkSize, @@ -220,6 +224,7 @@ async function cleanup(): Promise { if (execute && toRemove.length) { console.log('--- Removal request ---'); + awsRequests++; await s3.deleteObjects({ Delete: { Objects: toRemove, @@ -238,6 +243,7 @@ async function cleanup(): Promise { console.log(`Fresh: ${fresh}`); console.log(`Removed: ${removed}`); console.log(`Removed size: ${Math.round(removedSize / 1024 / 1024)} MB`); + console.log(`AWS requests: ${awsRequests}`); } cleanup();