fix(deployment): purge SystemArtifactDeploymentRecords in the terminal-record retention sweep (review 2026-10-21 08/G2)

This commit is contained in:
Joseph Doherty
2026-10-22 06:20:44 -04:00
parent da5a049077
commit d6a9a79c27
7 changed files with 138 additions and 4 deletions
@@ -285,6 +285,29 @@ public class DeploymentManagerRepository : IDeploymentManagerRepository
return Task.CompletedTask;
}
/// <inheritdoc />
public async Task<int> PurgeSystemArtifactDeploymentRecordsAsync(
DateTimeOffset cutoffUtc,
int batchSize,
CancellationToken cancellationToken = default)
{
// Same bounded-batch shape as PurgeTerminalDeploymentRecordsAsync: the caller
// re-invokes until fewer than batchSize rows come back. Every row is terminal by
// construction (it is written once, after the artifact sweep finished).
var stale = await _dbContext.SystemArtifactDeploymentRecords
.Where(d => d.DeployedAt < cutoffUtc)
.OrderBy(d => d.Id)
.Take(batchSize)
.ToListAsync(cancellationToken);
if (stale.Count == 0)
return 0;
_dbContext.SystemArtifactDeploymentRecords.RemoveRange(stale);
await _dbContext.SaveChangesAsync(cancellationToken);
return stale.Count;
}
// --- DeployedConfigSnapshot ---
/// <inheritdoc />