perf(alerts): look changesets up by id instead of hashing the whole table #506
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
gmackie/ForgeGraph!506
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "perf/settled-alerts-index-lookup"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Follow-up to #502, before it ships. #502 is merged but has never deployed — it is one of the commits stuck behind the registry-401 deploy blackout — so this corrects it while it is still unreleased rather than after.
The problem. The resolver joined on a computed key:
No index can serve that.
EXPLAIN (ANALYZE)on production:1.7ms is not slow. But it runs on every agent poll — roughly 840 times an hour across seven nodes — and the scan grows with the changesets table rather than with the handful of firing alerts it is actually about. That is the same shape as the unindexed poll that starved this database this morning (bob re-reading
session_event), so it is not a pattern to leave sitting in the agent hot path.The fix. The dedupe key already contains the changeset id, so the join was recovering something we already had. Read the firing alerts by index, parse the ids out of the keys, look them up by primary key:
0.37ms, and no sequential scan — cost now scales with firing alerts, not with total changesets.
Behaviour is unchanged: still resolve-only, still bounded, still leaves a genuinely open changeset alerting. 5 tests updated for the two-query shape, all green.
Caught because a peer flagged that the blackout will ship several commits at once unbisected and suggested reviewing mine before it goes out — worth doing, since this one touches the poll path.
CI note:
typecheckwill fail here on@preflight/runreportuntil #505 lands. That is the registry-401 blackout, not this change — the package cannot be installed at all right now, locally or in CI, and the failing files (run-report-provider.ts,runs/[testRunId]/page.tsx) are untouched by this diff.🤖 Generated with Claude Code