diff --git a/apps/web/src/hooks/use-bulk-import.ts b/apps/web/src/hooks/use-bulk-import.ts index 502c897..1774e11 100644 --- a/apps/web/src/hooks/use-bulk-import.ts +++ b/apps/web/src/hooks/use-bulk-import.ts @@ -73,32 +73,39 @@ export function useBulkImport(): BulkImportHook { setState((s) => ({ ...s, completed: alreadyCached })); + const batches: { code: string }[][] = []; for (let i = 0; i < uncached.length; i += BATCH_SIZE) { - const batch = uncached.slice(i, i + BATCH_SIZE); - // biome-ignore lint/performance/noAwaitInLoops: sequential batching is intentional to avoid overwhelming the server with too many concurrent requests - await Promise.allSettled( - batch.map(async ({ code }) => { - const url = getDefaultFetchUrl(code, baseUrl); - try { - await fetchAndCacheSource(code, url); - countersRef.current.completed++; - } catch (err) { - countersRef.current.failed++; - console.warn( - `[bulk-import] FAILED ${code} (${url}):`, - err instanceof Error ? err.message : err, - ); - } - setState({ - status: "loading", - total, - completed: countersRef.current.completed, - failed: countersRef.current.failed, - }); - }), - ); + batches.push(uncached.slice(i, i + BATCH_SIZE)); } + await batches.reduce( + (chain, batch) => + chain.then(() => + Promise.allSettled( + batch.map(async ({ code }) => { + const url = getDefaultFetchUrl(code, baseUrl); + try { + await fetchAndCacheSource(code, url); + countersRef.current.completed++; + } catch (err) { + countersRef.current.failed++; + console.warn( + `[bulk-import] FAILED ${code} (${url}):`, + err instanceof Error ? err.message : err, + ); + } + setState({ + status: "loading", + total, + completed: countersRef.current.completed, + failed: countersRef.current.failed, + }); + }), + ), + ), + Promise.resolve() as Promise, + ); + await refreshCache(); const { completed, failed } = countersRef.current; diff --git a/scripts/check-lint-ignores.mjs b/scripts/check-lint-ignores.mjs index 6ebd137..b4d552c 100644 --- a/scripts/check-lint-ignores.mjs +++ b/scripts/check-lint-ignores.mjs @@ -12,7 +12,7 @@ import { execSync } from "node:child_process"; import { readFileSync } from "node:fs"; // ── Configuration ────────────────────────────────────────────────────── -const MAX_SOURCE_IGNORES = 4; +const MAX_SOURCE_IGNORES = 3; const MAX_TEST_IGNORES = 3; /** Rule prefixes that must never be suppressed. */