Skip to content

Commit

Permalink
feat: use up to 110K keys when purging storage
Browse files Browse the repository at this point in the history
  • Loading branch information
aalemayhu committed Apr 1, 2023
1 parent 9a17b31 commit 3dd38b4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/lib/storage/StorageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ class StorageHandler {
});
}

getContents(): Promise<ObjectList | undefined> {
getContents(maxKeys: number = 1000): Promise<ObjectList | undefined> {
const { s3 } = this;
return new Promise((resolve, reject) => {
s3.listObjects(
{ Bucket: StorageHandler.DefaultBucketName() },
{ Bucket: StorageHandler.DefaultBucketName(), MaxKeys: maxKeys },
(err, data) => {
if (err) {
sendError(err);
Expand Down
3 changes: 2 additions & 1 deletion src/lib/storage/jobs/helpers/deleteOldUploads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Users[]> =>
db('users').where('patreon', 'false').returning(['owner']);
Expand All @@ -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;
`);
Expand Down

0 comments on commit 3dd38b4

Please sign in to comment.