fix cleanupImages

This commit is contained in:
Andrea Vos 2025-01-03 15:00:09 +01:00
parent 0b11db32b6
commit 81f6fdf3c2

View File

@ -14,7 +14,7 @@ const validateIds = (type: string, data: Record<string, boolean>, 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<void> {
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<void> {
if (execute && toRemove.length) {
console.log('--- Removal request ---');
awsRequests++;
await s3.deleteObjects({
Delete: {
Objects: toRemove,
@ -185,6 +188,7 @@ async function cleanup(): Promise<void> {
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<void> {
if (execute && toRemove.length) {
console.log('--- Removal request ---');
awsRequests++;
await s3.deleteObjects({
Delete: {
Objects: toRemove,
@ -238,6 +243,7 @@ async function cleanup(): Promise<void> {
console.log(`Fresh: ${fresh}`);
console.log(`Removed: ${removed}`);
console.log(`Removed size: ${Math.round(removedSize / 1024 / 1024)} MB`);
console.log(`AWS requests: ${awsRequests}`);
}
cleanup();