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:
@@ -79,6 +79,9 @@ public class WorkQueueService : IWorkQueueService
|
||||
string sortBy,
|
||||
string sortDirection)
|
||||
{
|
||||
pageSize = Math.Clamp(pageSize, 1, 100);
|
||||
page = Math.Max(1, page);
|
||||
|
||||
if (!_allowedSortFields.Contains(sortBy))
|
||||
throw new ValidationException(
|
||||
$"Invalid sortBy field '{sortBy}'. Allowed: {string.Join(", ", _allowedSortFields)}.",
|
||||
@@ -87,10 +90,8 @@ public class WorkQueueService : IWorkQueueService
|
||||
var totalCount = await query.CountAsync();
|
||||
var totalPages = (int)Math.Ceiling((double)totalCount / pageSize);
|
||||
|
||||
var sorted = ApplySort(query, sortBy, sortDirection);
|
||||
var sorted = ApplySort(query.AsNoTracking(), sortBy, sortDirection);
|
||||
var items = await sorted
|
||||
.Include(b => b.EnteredByUser)
|
||||
.Include(b => b.Events)
|
||||
.Skip((page - 1) * pageSize)
|
||||
.Take(pageSize)
|
||||
.Select(b => new WorkQueueItemResponse(
|
||||
@@ -128,23 +129,21 @@ public class WorkQueueService : IWorkQueueService
|
||||
statusCounts[status.ToDbString()] = count;
|
||||
}
|
||||
|
||||
var pendingBatches = await _db.DigitizationBatches
|
||||
var pendingQuery = _db.DigitizationBatches
|
||||
.AsNoTracking()
|
||||
.Where(b => b.Status == BatchStatus.PendingVerification)
|
||||
.Select(b => b.UpdatedAt)
|
||||
.ToListAsync();
|
||||
.Where(b => b.Status == BatchStatus.PendingVerification);
|
||||
|
||||
var pendingCount = await pendingQuery.CountAsync();
|
||||
double avgTimeInQueueMinutes = 0;
|
||||
double oldestPendingMinutes = 0;
|
||||
|
||||
if (pendingBatches.Count > 0)
|
||||
if (pendingCount > 0)
|
||||
{
|
||||
var ages = pendingBatches
|
||||
.Select(updatedAt => (now - updatedAt).TotalMinutes)
|
||||
.ToList();
|
||||
|
||||
avgTimeInQueueMinutes = ages.Average();
|
||||
oldestPendingMinutes = ages.Max();
|
||||
var oldestUpdatedAt = await pendingQuery.MinAsync(b => b.UpdatedAt);
|
||||
oldestPendingMinutes = (now - oldestUpdatedAt).TotalMinutes;
|
||||
avgTimeInQueueMinutes = await pendingQuery
|
||||
.Select(b => (now - b.UpdatedAt).TotalMinutes)
|
||||
.AverageAsync();
|
||||
}
|
||||
|
||||
var cutoff = now.AddHours(-24);
|
||||
@@ -177,7 +176,7 @@ public class WorkQueueService : IWorkQueueService
|
||||
|
||||
_logger.LogDebug(
|
||||
"Work queue overview: {PendingCount} pending, avg queue {AvgMinutes:F1}m, reject rate {RejectRate:P1}",
|
||||
pendingBatches.Count, avgTimeInQueueMinutes, rejectRate);
|
||||
pendingCount, avgTimeInQueueMinutes, rejectRate);
|
||||
|
||||
return new WorkQueueOverviewResponse
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user