fix(hub): BIT-29730 stop timeout on GET recent-errors?status=resolved
CI / Test ingest-api (pull_request) Successful in 1m13s
CI / Test api (pull_request) Successful in 1m12s
CI / Lint and typecheck admin-ui (pull_request) Successful in 1m45s
CI / Validate Docker build (pull_request) Successful in 5m11s

recent-errors built its result by ranking ALL occurrences of every
matching incident with ROW_NUMBER() before applying LIMIT, so
status=resolved (the majority, longest-lived incident state) forced a
scan of the full historical occurrence log just to return one page.
admin/incidents.ts already filters/orders er_incidents directly for
this reason; apply the same pattern here: page through er_incidents
first (small, indexed by current_state), then rank occurrences only
for that page. The q= search path is kept on the old occurrence-first
query since it needs to match occurrence content across an incident's
full history.

Adds er_incidents_state_seen_idx (current_state, last_seen_at) so the
new incident-first path stays indexed even without a project_slug
filter, and backfills the docker/local migration runners that had
drifted behind deploy/lxc/run-migrate.sh (missing three prior
migrations), since the new migration needs to run through them too.

Verified locally against MariaDB (docker compose) with 3k resolved /
20 open incidents and ~90k synthetic occurrences: the reported repro
curls now return HTTP 200 in <100ms (previously reproduced as a hang
via manual EXPLAIN/timing of the old query, ~2s at this seed size and
scaling with total occurrence history).
This commit is contained in:
David Santos committed 2026-08-24 08:32:26 +01:00
1 parent 308ff624cf
commit 7987aa94ae
7 files changed
+123 -15

No files matched your search

@@ -0,0 +1,5 @@
BEGIN;
DROP INDEX IF EXISTS er_incidents_state_seen_idx ON er_incidents;
COMMIT;
@@ -0,0 +1,11 @@
BEGIN;
-- BIT-29730: GET /api/error-monitoring/recent-errors timed out for status=resolved.
-- er_incidents_project_state_seen_idx (project_id, current_state, last_seen_at DESC)
-- only helps when project_slug is also filtered. recent-errors now filters/paginates
-- er_incidents by current_state alone (no project_id) before touching occurrences,
-- so add a state-only index to support that lookup.
CREATE INDEX IF NOT EXISTS er_incidents_state_seen_idx
ON er_incidents (current_state, last_seen_at DESC);
COMMIT;