feat(cache): purge soft-deleted package rows after a retention period

The cleanup worker now hard-deletes package rows whose deleted_at is
older than cache.deleted_retention. The default is 30 days. A value of
0 keeps the rows. The purge runs in bounded batches, with at most 100
batches per cleanup pass, and removes child rows with the package.

History tables have no foreign key to packages, and stats_snapshots
holds its own counts, so the purge leaves both untouched. The cleanup
log line now reports purged_deleted and deleted_retention.
This commit is contained in:
2026-11-23 14:55:26 +00:00
parent 1512230ab3
commit ba8bc392ec
13 changed files with 360 additions and 7 deletions
+5
View File
@@ -86,6 +86,11 @@ type MetadataStore interface {
// the given time, oldest first. A limit <= 0 means DefaultBatchSize.
ListExpiredPackages(ctx context.Context, expiredBefore time.Time, limit int) ([]*Package, error)
// PurgeDeletedPackages hard-deletes up to limit soft-deleted packages whose
// deletion is older than deletedBefore, with their scan and vulnerability
// rows, and returns the number removed. A limit <= 0 means DefaultBatchSize.
PurgeDeletedPackages(ctx context.Context, deletedBefore time.Time, limit int) (int64, error)
// GetStatsTrend returns the daily stats snapshots from the UTC day of since
// on, oldest first. Backends without history return none.
GetStatsTrend(ctx context.Context, since time.Time) ([]*StatsSnapshot, error)