Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{
"id": "s3",
"name": "S3",
"version": "0.1.8",
"version": "0.1.9",
"description": "S3 and S3-compatible backend support.",
"icon": "server",
"main": "https://sync.consensia.cc/modules/s3.js",
Expand Down
5 changes: 2 additions & 3 deletions packages/s3/src/optimizer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { OptimizerInput, OptimizerOutput } from '@hesprs/sync-engine-sdk';
import type { DeleteAtom, OptimizerInput, OptimizerOutput } from '@hesprs/sync-engine-sdk';
import { digOriginal } from '@hesprs/sync-engine-sdk';
import S3Fs, { BATCH_DELETE_MAX_KEYS } from './s3/fs';

Expand All @@ -9,10 +9,9 @@ export default function s3BatchDeleteOptimizer({
const original = digOriginal(fs);
if (!(original instanceof S3Fs)) return undefined;
const s3Fs = original;
type DeleteAtom = Extract<(typeof atoms)[number], { type: 'delete' }>;
const deleteAtoms = atoms.filter((a): a is DeleteAtom => a.type === 'delete');
if (deleteAtoms.length <= 1) return atoms;
const otherAtoms = atoms.filter((a) => a.type !== 'delete');
if (deleteAtoms.length === 0) return atoms;
const batchGroups: Array<Array<DeleteAtom>> = [];
for (let i = 0; i < deleteAtoms.length; i += BATCH_DELETE_MAX_KEYS)
batchGroups.push(deleteAtoms.slice(i, i + BATCH_DELETE_MAX_KEYS));
Expand Down
25 changes: 25 additions & 0 deletions packages/s3/test/fs-s3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,31 @@ test('batch delete rejects only atoms with S3 partial failures', async () => {
);
});

test('batchDelete retries each key individually when the batch request fails', async () => {
const s3 = createS3Fs();
const methods: Array<string> = [];
parsedResponse = { Error: { Code: 'InternalError', Message: 'boom' } };
s3.setRequest((url, params) => {
methods.push(params.method ?? '');
if (params.method === 'POST')
return response({
status: 500,
text: '<Error><Code>InternalError</Code><Message>boom</Message></Error>',
});
expect(params.method).toBe('DELETE');
if (url.endsWith('/broken.md'))
return response({
status: 500,
text: '<Error><Code>InternalError</Code><Message>boom</Message></Error>',
});
return response({ status: 204 });
});
const result = await s3.fs.batchDelete(['ok.md', 'broken.md']);
expect(result['ok.md']).toBe(true);
expect(result['broken.md']).toBe('S3 InternalError: boom');
expect(methods).toStrictEqual(['POST', 'DELETE', 'DELETE']);
});

test('move copies encoded source before deleting old key', async () => {
const s3 = createS3Fs();
s3.setRequest((url, params) => {
Expand Down
Loading