From fab63f9f8c11b1a454030feaf40b39aa1d7dd37a Mon Sep 17 00:00:00 2001 From: MechaCat02 Date: Thu, 28 May 2026 19:23:55 +0200 Subject: [PATCH] chore: drop dead 'failed' branch from crawler_jobs partial index MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 0012_crawler.sql's partial index on `state IN ('pending','failed')` indexes a state that no code path ever writes — ack_failed in crawler/jobs.rs only ever moves jobs to 'dead' or 'pending'. The 'failed' branch costs a write on every state change without ever matching a query. Drop it; the CHECK still allows 'failed' so a future migration can re-introduce it cleanly. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../0016_crawler_jobs_drop_failed_state.sql | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 backend/migrations/0016_crawler_jobs_drop_failed_state.sql diff --git a/backend/migrations/0016_crawler_jobs_drop_failed_state.sql b/backend/migrations/0016_crawler_jobs_drop_failed_state.sql new file mode 100644 index 0000000..bc64f55 --- /dev/null +++ b/backend/migrations/0016_crawler_jobs_drop_failed_state.sql @@ -0,0 +1,15 @@ +-- The original 0012 partial index covers `state IN ('pending','failed')`, +-- but `ack_failed` in src/crawler/jobs.rs only writes `dead` or +-- `pending` — `failed` is never set. The index branch on `failed` +-- never matches any row, so it's dead weight on every write. +-- +-- Drop and recreate the index without the dead branch. The CHECK +-- constraint on `state` still allows `'failed'` so a future migration +-- can adopt that terminal-but-retryable state without a second +-- schema change. + +DROP INDEX IF EXISTS crawler_jobs_ready_idx; + +CREATE INDEX crawler_jobs_ready_idx + ON crawler_jobs (scheduled_at) + WHERE state = 'pending';