feat: PhotoPrism M0 bring-up — compose stack, web client, sidecar, migrate
Replace the legacy mule-image backend with PhotoPrism plus a thin SvelteKit client and a Node sidecar for endpoints PhotoPrism doesn't expose (file rename), and add a two-phase migrator (metadata via PUT, heaps → albums) for the existing Postgres library. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
50
web/src/lib/services/batch.ts
Normal file
50
web/src/lib/services/batch.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Fan-out helper used wherever PhotoPrism lacks a true batch endpoint.
|
||||
* Bounded concurrency keeps the indexer happy on slow hosts; each item's
|
||||
* result is collected and the aggregate `{updated, errors[]}` mirrors the
|
||||
* shape the legacy mule-image bulk endpoint returned, so existing toast
|
||||
* + undo plumbing slots in without changes.
|
||||
*/
|
||||
|
||||
export interface BatchResult<T> {
|
||||
updated: T[];
|
||||
errors: { id: string; message: string }[];
|
||||
}
|
||||
|
||||
export interface BatchOptions {
|
||||
concurrency?: number;
|
||||
onProgress?: (done: number, total: number) => void;
|
||||
}
|
||||
|
||||
export async function batchEdit<T>(
|
||||
ids: string[],
|
||||
fn: (id: string) => Promise<T>,
|
||||
opts: BatchOptions = {}
|
||||
): Promise<BatchResult<T>> {
|
||||
const concurrency = Math.max(1, opts.concurrency ?? 8);
|
||||
const updated: T[] = [];
|
||||
const errors: { id: string; message: string }[] = [];
|
||||
let i = 0;
|
||||
let done = 0;
|
||||
|
||||
async function worker() {
|
||||
while (true) {
|
||||
const idx = i++;
|
||||
if (idx >= ids.length) return;
|
||||
const id = ids[idx];
|
||||
try {
|
||||
updated.push(await fn(id));
|
||||
} catch (err) {
|
||||
errors.push({ id, message: err instanceof Error ? err.message : String(err) });
|
||||
} finally {
|
||||
done++;
|
||||
opts.onProgress?.(done, ids.length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await Promise.all(
|
||||
Array.from({ length: Math.min(concurrency, ids.length) }, () => worker())
|
||||
);
|
||||
return { updated, errors };
|
||||
}
|
||||
Reference in New Issue
Block a user