fix(site-call-audit): KPI snapshots as single conditional-aggregate queries (review 2026-10-21 06/PERF-3, 08/P3)

This commit is contained in:
Joseph Doherty
2026-10-22 09:23:53 -04:00
parent 811a561885
commit e7fb71c2de
3 changed files with 240 additions and 145 deletions
@@ -209,6 +209,13 @@ mirroring the Notification Outbox KPI shape:
- Stuck count — `Pending`/`Retrying` older than a configurable threshold
(default 10 minutes); display-only, no escalation.
Each snapshot (global, per-site, per-node) is **one conditional-aggregation
query** over the rows that contribute to at least one metric (non-terminal,
Parked, or Delivered/Failed inside the interval), with the oldest-pending age a
`MIN` over a `CASE` in the same scan — the same shape as the Notification
Outbox repository. (It used to cost 7 / 6 / 6 sequential round trips, paid by
the 10 s dashboard poll and the per-minute KPI sampler.)
## Retention
Daily purge of terminal rows (`Delivered`, `Failed`, `Discarded`) after a