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
@@ -138,6 +138,7 @@ public class PromotionService : IPromotionService
public async Task<PromotionResultResponse> GetPromotionResultAsync(Guid batchId)
{
var batch = await _db.DigitizationBatches
.AsNoTracking()
.FirstOrDefaultAsync(b => b.Id == batchId);
if (batch is null)
@@ -150,6 +151,7 @@ public class PromotionService : IPromotionService
// Retrieve the live patient by looking up the encounter
var encounter = await _db.Encounters
.AsNoTracking()
.Include(e => e.Patient)
.FirstOrDefaultAsync(e => e.Id == batch.PromotionEncounterId);
@@ -159,6 +161,7 @@ public class PromotionService : IPromotionService
"PROMOTION_ENCOUNTER_NOT_FOUND");
var observationIds = await _db.Observations
.AsNoTracking()
.Where(o => o.SourceBatchId == batchId)
.Select(o => o.Id)
.ToArrayAsync();
@@ -324,8 +327,10 @@ public class PromotionService : IPromotionService
if (draft.DateOfBirth.HasValue)
{
var sameDobPatients = await _db.Patients
.AsNoTracking()
.Where(p => p.DateOfBirth == draft.DateOfBirth)
.Select(p => new { p.Id, p.Mrn, p.FullName })
.Take(50)
.ToListAsync();
foreach (var candidate in sameDobPatients)
@@ -603,13 +608,14 @@ public class PromotionService : IPromotionService
return Task.FromResult((observationIds.ToArray(), outboxCount));
}
public async Task<PromotionResult> PromoteAsync(Guid batchId, Guid actorUserId)
public async Task<PromotionResult> PromoteAsync(
Guid batchId, Guid actorUserId, CancellationToken ct = default)
{
var stopwatch = Stopwatch.StartNew();
try
{
await using var transaction = await _db.Database.BeginTransactionAsync();
await using var transaction = await _db.Database.BeginTransactionAsync(ct);
try
{
@@ -617,7 +623,7 @@ public class PromotionService : IPromotionService
.Include(b => b.DraftPatient)
.Include(b => b.DraftEncounter)
.Include(b => b.DraftObservations)
.FirstOrDefaultAsync(b => b.Id == batchId);
.FirstOrDefaultAsync(b => b.Id == batchId, ct);
if (batch is null)
throw new NotFoundException("Batch not found.", "BATCH_NOT_FOUND");
@@ -635,8 +641,8 @@ public class PromotionService : IPromotionService
var core = await ExecutePromotionCoreAsync(
batch, actorUserId, enableRetroactiveAlerts, now);
await _db.SaveChangesAsync();
await transaction.CommitAsync();
await _db.SaveChangesAsync(ct);
await transaction.CommitAsync(ct);
stopwatch.Stop();
DiagnosticsMetrics.PromotionDuration.Observe(stopwatch.Elapsed.TotalSeconds);