Harden API memory and CPU usage across Phases 19–22.
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:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user