Bound list/PDF payloads, stream MinIO I/O with cancellation, paginate history and FHIR $everything, tighten OCR lifetimes/buffers, and add phase tracking docs.
4.0 KiB
4.0 KiB
Phase 19 — Bounds and Read-Path Hygiene
What exists
- List endpoints accept
page/pageSizewithout a service-layer clamp:BatchService.ListAsync,WorkQueueService.BuildQueueResponseAsync,CoverSheetService.ListAsync.BatchEventServicealready clamps to 200. - Cover-sheet create clamps
Countto 100;GenerateBatchPdfaccepts unboundedBatchPdfRequest.CoverSheetIds. - Read queries often omit
AsNoTracking;VerificationService.VerifyAsyncincludes unusedEvents. GetDocumentcalls fullGetByIdAsync(drafts + observations).FhirJsonOutputFormatterconstructs a Pretty serializer per response.
Tracker: performance-hardening-overview.md.
What needs to be built
Prevent single-request memory/CPU blowups and cut unnecessary EF tracking and over-fetch. Low risk; no MinIO/OCR/history pagination in this phase.
Do not start Phase 20 until success criteria below pass.
Step 1 — Clamp pagination in services
In BatchService.ListAsync, WorkQueueService.BuildQueueResponseAsync, and CoverSheetService.ListAsync:
pageSize = Math.Clamp(pageSize, 1, 100);
page = Math.Max(1, page);
Clamp in the service layer so all callers are safe.
Step 2 — Cap batch cover-sheet PDF IDs
- Reject or truncate
CoverSheetIdsto max 100 (align with create clamp) inCoverSheetController.GenerateBatchPdforCoverSheetService.GetByIdsAsync. - Prefer
ValidationExceptionwhen count > 100 so clients get a clear error.
Step 3 — AsNoTracking and unused Includes
- Add
AsNoTracking()on read-only paths: batch list; cover-sheet lookups that do not mutate; promotion result reads where tracked entities are not updated. - Remove
.Include(b => b.Events)fromVerificationService.VerifyAsyncif Events are unused. - Keep tracking on mutation paths (verify/approve/assign/promote).
Step 4 — Slim GetDocument
- Stop calling
GetByIdAsyncfor document streaming. - Query only
DocumentRef(and not-found) plusScannedDocuments.ContentType. - Preserve document-access audit behavior.
Step 5 — FHIR serializer reuse
- Static/
LazyFhirJsonSerializerwithPretty = false. - Avoid allocating a new serializer (and pretty whitespace) on every FHIR write.
Success criteria
pageSize=1000000on batch list / work-queue / cover-sheet list returns ≤ 100 items- Batch PDF with > 100 IDs fails validation (or is hard-capped) — documented in API behavior
GetDocumentdoes not load draft graphs; still returns 200 for seeded batches with objects- Verification still succeeds without loading Events collection
- FHIR JSON responses are compact (not pretty-printed)
dotnet testonVigilCareRecordsAPI.Testspasses
Out of scope
- MinIO async download / upload streaming (Phase 20)
- Patient history /
$everythingpagination (Phase 20) - OCR changes (Phase 21)
Verification
dotnet test VigilCareRecordsAPI.Tests/VigilCareRecordsAPI.Tests.csproj- Manual or test: list with oversized
pageSize; GetDocument on a seeded batch; FHIR Patient read payload is single-line/compact JSON - Update overview finding statuses 5, 8, 10, 11 → Done when this phase merges
Gate
Do not start Phase 20 until success criteria above are met.