Skip to content

Commit b07993b

Browse files
committed
fix(store): correctly remove unused file transforms
This bug has existed for a while, where we had a higher number of file transform jobs than expected. This seems to be the culprit.
1 parent 3b784ef commit b07993b

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

packages/store/src/file.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ async function fileCheckContentType(options, props, source) {
343343
export async function fileSyncDeletedWithObjectStorage(sql, s3Client, options) {
344344
// Delete transformations where the original is already removed
345345
await queries.fileDelete(sql, {
346-
$raw: query`meta->>'transformedFromOriginal' IS NOT NULL AND NOT EXISTS (SELECT FROM "file" f2 WHERE f2.id = (meta->>'transformedFromOriginal')::uuid)`,
346+
$raw: query`meta->>'transformedFromOriginal' IS NOT NULL AND NOT EXISTS (SELECT FROM "file" f2 WHERE f2.id = (f.meta->>'transformedFromOriginal')::uuid)`,
347347
});
348348

349349
const objectsInStore = (
@@ -355,6 +355,8 @@ export async function fileSyncDeletedWithObjectStorage(sql, s3Client, options) {
355355
}).execRaw(sql)
356356
).map((it) => it.id);
357357

358+
// S3 supports up to 1000 deletions in a single request
359+
const maxSetSize = 999;
358360
const deletingSet = [];
359361

360362
for await (const part of objectStorageListObjects(s3Client, {
@@ -379,22 +381,17 @@ export async function fileSyncDeletedWithObjectStorage(sql, s3Client, options) {
379381
return;
380382
}
381383

382-
// S3 supports up to 1000 deletions in a single request
383-
const maxSetSize = 999;
384-
const deleteCommands = [];
385-
386384
while (deletingSet.length) {
387-
deleteCommands.push({
388-
Bucket: options.bucketName,
389-
Delete: {
390-
Objects: deletingSet.splice(0, maxSetSize),
391-
},
392-
});
385+
await s3Client.send(
386+
new DeleteObjectsCommand({
387+
Bucket: options.bucketName,
388+
Delete: {
389+
Objects: deletingSet.splice(0, maxSetSize),
390+
Quiet: true,
391+
},
392+
}),
393+
);
393394
}
394-
395-
await Promise.all(
396-
deleteCommands.map((it) => s3Client.send(new DeleteObjectsCommand(it))),
397-
);
398395
}
399396

400397
/**

0 commit comments

Comments
 (0)