diff --git a/src/lib/storage/StorageHandler.ts b/src/lib/storage/StorageHandler.ts index 7ddea8da1..3f36a80ed 100644 --- a/src/lib/storage/StorageHandler.ts +++ b/src/lib/storage/StorageHandler.ts @@ -57,11 +57,11 @@ class StorageHandler { }); } - getContents(): Promise { + getContents(maxKeys: number = 1000): Promise { const { s3 } = this; return new Promise((resolve, reject) => { s3.listObjects( - { Bucket: StorageHandler.DefaultBucketName() }, + { Bucket: StorageHandler.DefaultBucketName(), MaxKeys: maxKeys }, (err, data) => { if (err) { sendError(err); diff --git a/src/lib/storage/jobs/helpers/deleteOldUploads.ts b/src/lib/storage/jobs/helpers/deleteOldUploads.ts index 1607221d8..da97308eb 100644 --- a/src/lib/storage/jobs/helpers/deleteOldUploads.ts +++ b/src/lib/storage/jobs/helpers/deleteOldUploads.ts @@ -7,6 +7,7 @@ import StorageHandler from '../../StorageHandler'; import { Upload } from '../../types'; export const MS_21 = TIME_21_MINUTES_AS_SECONDS * 1000; +const MAX_KEYS = 110_000; const getFreeUsers = (db: Knex): Promise => db('users').where('patreon', 'false').returning(['owner']); @@ -27,7 +28,7 @@ export default async function deleteOldUploads(db: Knex) { await db('uploads').delete().where('key', upload.key); } - const files = await storage.getContents(); + const files = await storage.getContents(MAX_KEYS); const query = await db.raw(` SELECT up.key FROM users u JOIN uploads up ON u.id = up.owner WHERE u.patreon = true; `);