Harden API memory and CPU usage across Phases 19–22.
CI / changes (push) Successful in 17s
dotnet8-ci / build-and-test (push) Successful in 8m23s
CI / backend (push) Successful in 8m24s
node-ci / build (push) Failing after 2m1s
CI / frontend (push) Failing after 2m2s

Bound list/PDF payloads, stream MinIO I/O with cancellation, paginate history and FHIR $everything, tighten OCR lifetimes/buffers, and add phase tracking docs.
This commit is contained in:
2026-11-30 23:55:56 +08:00
parent 192cb36dc7
commit a17bc2b734
46 changed files with 1677 additions and 215 deletions
@@ -61,17 +61,35 @@ public static class SeedDocumentStorage
logger.LogInformation("Seeded {Count} missing ScannedDocument rows", missingDocs.Count);
}
// Prefer ensuring objects only for keys we just registered as missing docs,
// plus a single pass for remaining keys via EnsureObjectAsync (Stat+Put if needed).
// Cap bootstrap MinIO work so restarts on large DBs stay bounded.
const int maxObjectEnsuresPerBootstrap = 200;
var keysToEnsure = missingDocs
.Select(d => d.ObjectKey)
.Concat(batches.Select(b => b.DocumentRef))
.Distinct(StringComparer.Ordinal)
.Take(maxObjectEnsuresPerBootstrap)
.ToList();
var uploaded = 0;
foreach (var batch in batches)
foreach (var objectKey in keysToEnsure)
{
ct.ThrowIfCancellationRequested();
if (!await storage.ObjectExistsAsync(batch.DocumentRef))
if (!await storage.ObjectExistsAsync(objectKey, ct))
{
await storage.EnsureObjectAsync(batch.DocumentRef, MinimalPdf, "application/pdf");
await storage.EnsureObjectAsync(objectKey, MinimalPdf, "application/pdf", ct);
uploaded++;
}
}
if (batches.Count > maxObjectEnsuresPerBootstrap)
{
logger.LogWarning(
"SeedDocumentStorage capped MinIO ensure at {Cap} of {Total} batch keys; remaining keys will be ensured on later bootstraps or first access",
maxObjectEnsuresPerBootstrap, batches.Count);
}
if (uploaded > 0)
logger.LogInformation("Uploaded {Count} placeholder scan PDFs to object storage", uploaded);
}