perf(sql): sweep/KPI covering indexes + sliced notification terminal purge

This commit is contained in:
Joseph Doherty
2026-08-14 19:55:48 -04:00
parent 0b201e410c
commit 600659d579
8 changed files with 2265 additions and 3 deletions
@@ -70,5 +70,18 @@ public class NotificationOutboxConfiguration : IEntityTypeConfiguration<Notifica
builder.HasIndex(n => new { n.Status, n.NextAttemptAt });
builder.HasIndex(n => new { n.SourceSiteId, n.CreatedAt });
// Covers ComputeKpisAsync's "DeliveredLastInterval" count
// (Status == Delivered && DeliveredAt >= deliveredSince): filtered to just the
// Delivered rows so the index stays small relative to the full table and the KPI
// query can seek it directly instead of scanning every status (arch-review WP1.4).
// Status is stored as its enum name (HasConversion<string>() above), so the filter
// predicate matches on the literal 'Delivered', not the underlying int value.
// No N'' prefix: the value is ASCII-only (fine on SQL Server's nvarchar column)
// and the repository tests' SQLite provider rejects the T-SQL N'' national-string
// literal syntax outright when EnsureCreated() runs this filter as DDL.
builder.HasIndex(n => n.DeliveredAt)
.HasDatabaseName("IX_Notifications_Delivered")
.HasFilter("[Status] = 'Delivered'");
}
}