DB: indexes for the polling queries

- jobs(finished_at): the live view's "open or finished in the last 5 minutes"
  query, run once a second per visible tab, was a full scan of the job
  history; it is now a multi-index lookup (0.23 -> 0.04 ms at 2,000 jobs).
- benchmark_runs(state, created_at): the worker's look for the next queued run
  every 2 s scanned every run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EooZ9biu7kFNB4eDJrwQc5
This commit is contained in:
Claude committed 2026-11-01 21:04:45 +00:00
1 parent 6f4932e04d
commit 6b779debf7
5 files changed
+1549 -2

No files matched your search

+11 -2
View File
@@ -243,7 +243,12 @@ export const jobs = sqliteTable(
createdAt: createdAt(),
updatedAt: updatedAt(),
},
(t) => [index("jobs_state_idx").on(t.state), index("jobs_model_idx").on(t.modelId)],
(t) => [
index("jobs_state_idx").on(t.state),
index("jobs_model_idx").on(t.modelId),
// The live view polls open jobs plus recently finished ones once a second.
index("jobs_finished_idx").on(t.finishedAt),
],
);
export const jobFiles = sqliteTable(
@@ -719,7 +724,11 @@ export const benchmarkRuns = sqliteTable(
description: text("description"),
createdAt: createdAt(),
},
(t) => [index("benchmark_runs_created_idx").on(t.createdAt)],
(t) => [
index("benchmark_runs_created_idx").on(t.createdAt),
// The worker looks for the next queued run every 2 s.
index("benchmark_runs_state_idx").on(t.state, t.createdAt),
],
);
export const benchmarkLogs = sqliteTable(