Fix Kafka retry seek, bound buffers, and cut hot-path CPU/memory waste (Phases 41–44).
CI / changes (push) Successful in 17s
CI / frontend (push) Skipped
CI / backend (push) Successful in 15m10s

Stop consumers from committing past failed offsets, harden Rabbit/DataLake/gateway backpressure, dispose JsonDocument/MinIO correctly, and batch expensive DB/HTTP paths. Track progress in docs/performance.
This commit is contained in:
2026-11-30 21:32:43 +08:00
parent 1c1065938f
commit 68a2ab3204
54 changed files with 959 additions and 311 deletions
@@ -2,6 +2,8 @@ using Microsoft.EntityFrameworkCore;
public class PatientPhiMigrationService : IHostedService
{
private const int BatchSize = 500;
private readonly IServiceProvider _services;
private readonly ILogger<PatientPhiMigrationService> _logger;
@@ -19,26 +21,47 @@ public class PatientPhiMigrationService : IHostedService
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
var crypto = scope.ServiceProvider.GetRequiredService<IPhiEncryptionService>();
var patients = await db.Patients.ToListAsync(ct);
var migrated = 0;
var totalMigrated = 0;
Guid? afterId = null;
foreach (var patient in patients)
while (!ct.IsCancellationRequested)
{
if (patient.NameSearchToken is not null && crypto.IsEncrypted(patient.FirstName))
continue;
IQueryable<Patient> query = db.Patients.OrderBy(p => p.Id);
if (afterId is Guid cursor)
query = query.Where(p => p.Id.CompareTo(cursor) > 0);
patient.NameSearchToken = crypto.ComputeNameSearchToken(
patient.FirstName, patient.LastName);
migrated++;
var batch = await query.Take(BatchSize).ToListAsync(ct);
if (batch.Count == 0)
break;
afterId = batch[^1].Id;
var migrated = 0;
foreach (var patient in batch)
{
if (patient.NameSearchToken is not null && crypto.IsEncrypted(patient.FirstName))
continue;
patient.NameSearchToken = crypto.ComputeNameSearchToken(
patient.FirstName, patient.LastName);
migrated++;
}
if (migrated > 0)
{
await db.SaveChangesAsync(ct);
totalMigrated += migrated;
}
db.ChangeTracker.Clear();
}
if (migrated > 0)
if (totalMigrated > 0)
{
await db.SaveChangesAsync(ct);
_logger.LogInformation(
"PHI migration: updated {Count} patient search tokens", migrated);
"PHI migration: updated {Count} patient search tokens", totalMigrated);
}
}
public Task StopAsync(CancellationToken ct) => Task.CompletedTask;
}
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}