Skip to content

Commit

Permalink
Merge pull request #400 from lepikhinb/chunk-keys-to-delete
Browse files Browse the repository at this point in the history
Chunk deleted files into batches
  • Loading branch information
mnapoli authored Aug 31, 2024
2 parents 8c2716c + 4854e6c commit 7cdbb93
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/utils/s3-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,24 @@ export async function s3Sync({
const targetKeys = filesToUpload.map((file) =>
targetPathPrefix !== undefined ? path.posix.join(targetPathPrefix, file) : file
);

const keysToDelete = findKeysToDelete(Object.keys(existingS3Objects), targetKeys);
if (keysToDelete.length > 0) {
keysToDelete.map((key) => {
getUtils().log.verbose(`Deleting ${key}`);
fileChangeCount++;
});
await s3Delete(aws, bucketName, keysToDelete);
const batch = chunk(keysToDelete, 1000);

await Promise.all(
batch.map(async (keysToDeleteChunk, index) => {
getUtils().log.verbose(`Deleting chunk #${index}`);

keysToDeleteChunk.map((key) => {
getUtils().log.verbose(`Deleting ${key}`);
fileChangeCount++;
});

await s3Delete(aws, bucketName, keysToDeleteChunk);
})
);

hasChanges = true;
}

Expand Down

0 comments on commit 7cdbb93

Please sign in to comment.