GET /api/error-monitoring/recent-errors?status=resolved timed out (25s+) because the query ranked ALL occurrences of every matching incident with ROW_NUMBER() before applying LIMIT. Since resolved is the majority/longest-lived incident state, this forced a full scan of the historical occurrence log just to return one page.
Fix
Page through er_incidents first (small table, indexed by current_state), then rank occurrences only for that page — same pattern already used by admin/incidents.ts. The q= search path is kept on the old occurrence-first query since it needs to match 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. Also backfills scripts/docker-migrate.sh / scripts/run-mysql-migrations.sh, which had drifted behind deploy/lxc/run-migrate.sh (missing three prior migrations) — the new migration needs to run through all three runners.
Verification
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, ~2s at this seed size and scaling with total occurrence history). Added regression test in recentErrors.test.ts (6/6 passing).
Deploy note
The new migration (20260824120000_add_incidents_state_seen_idx) must run on the hub DB before/at deploy — covered by the three migration runners updated in this PR.
Fixes BIT-29730.
## Problem
`GET /api/error-monitoring/recent-errors?status=resolved` timed out (25s+) because the query ranked ALL occurrences of every matching incident with `ROW_NUMBER()` before applying `LIMIT`. Since `resolved` is the majority/longest-lived incident state, this forced a full scan of the historical occurrence log just to return one page.
## Fix
Page through `er_incidents` first (small table, indexed by `current_state`), then rank occurrences only for that page — same pattern already used by `admin/incidents.ts`. The `q=` search path is kept on the old occurrence-first query since it needs to match 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. Also backfills `scripts/docker-migrate.sh` / `scripts/run-mysql-migrations.sh`, which had drifted behind `deploy/lxc/run-migrate.sh` (missing three prior migrations) — the new migration needs to run through all three runners.
## Verification
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, ~2s at this seed size and scaling with total occurrence history). Added regression test in `recentErrors.test.ts` (6/6 passing).
## Deploy note
The new migration (`20260824120000_add_incidents_state_seen_idx`) must run on the hub DB before/at deploy — covered by the three migration runners updated in this PR.
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).
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Fixes BIT-29730.
Problem
GET /api/error-monitoring/recent-errors?status=resolvedtimed out (25s+) because the query ranked ALL occurrences of every matching incident withROW_NUMBER()before applyingLIMIT. Sinceresolvedis the majority/longest-lived incident state, this forced a full scan of the historical occurrence log just to return one page.Fix
Page through
er_incidentsfirst (small table, indexed bycurrent_state), then rank occurrences only for that page — same pattern already used byadmin/incidents.ts. Theq=search path is kept on the old occurrence-first query since it needs to match 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 aproject_slugfilter. Also backfillsscripts/docker-migrate.sh/scripts/run-mysql-migrations.sh, which had drifted behinddeploy/lxc/run-migrate.sh(missing three prior migrations) — the new migration needs to run through all three runners.Verification
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, ~2s at this seed size and scaling with total occurrence history). Added regression test in
recentErrors.test.ts(6/6 passing).Deploy note
The new migration (
20260824120000_add_incidents_state_seen_idx) must run on the hub DB before/at deploy — covered by the three migration runners updated in this PR.auto-approve: CI success (gitea_auto_approve_open_prs_once.py)
auto-approve: CI success (gitea_auto_approve_open_prs_once.py)
auto-approve: CI success (gitea_auto_approve_open_prs_once.py)