perf: dedupe the overview poll and index the jobs rollup
Measured on the deployed console: the page shell and every module land in 39ms, so the 1.4s was entirely /admin/api/ops/overview, fetched twice. Twice because the sidebar and the overview view each called usePoll on the same url, each with its own timer. usePoll now keeps one store per url, so any number of subscribers share a single request and a single interval, and a request already on the wire is joined rather than duplicated. The endpoint itself was dominated by the jobs rollup: a full scan of autonomy_jobs, 521k rows and growing about nine thousand a day. A covering index on (job_type, lane, status, created_at) takes it from 548ms to 110ms. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WnNxwxfXSbeNtjvtz5gayb
This commit is contained in:
@@ -244,6 +244,12 @@ function initAutonomySchema(db) {
|
||||
'ALTER TABLE autonomy_calibration_snapshots ADD COLUMN replay_run_id INTEGER',
|
||||
'ALTER TABLE autonomy_calibration_snapshots ADD COLUMN distinct_instruments INTEGER',
|
||||
'ALTER TABLE autonomy_calibration_snapshots ADD COLUMN top_instrument_share REAL',
|
||||
// The dashboard groups jobs by type/lane/status on every poll. autonomy_jobs is
|
||||
// half a million rows and grows by roughly nine thousand a day from the archive
|
||||
// reconcile loop, so without this that one query was 548ms and rising.
|
||||
// created_at is included to keep the MAX() index-only.
|
||||
'CREATE INDEX IF NOT EXISTS idx_autonomy_jobs_group ON autonomy_jobs(job_type, lane, status, created_at)',
|
||||
'CREATE INDEX IF NOT EXISTS idx_calibration_snapshot_latest ON autonomy_calibration_snapshots(cohort_key, source, id)',
|
||||
]) {
|
||||
try {
|
||||
db.exec(statement);
|
||||
|
||||
Reference in New Issue
Block a user