From 7bd0142734296931ebedb883e71fac02459cf664 Mon Sep 17 00:00:00 2001 From: Simon Diesenreiter Date: Sat, 14 Nov 2026 12:23:27 +0100 Subject: [PATCH] Partial index for claims still awaiting topic tagging Each enrich.topics batch scanned all claims for untagged ones; after the history backfill a run took hours and blocked the enrich queue. Co-Authored-By: Claude Opus 5.5 --- backend/migrations/0006_untagged_claims_index.sql | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 backend/migrations/0006_untagged_claims_index.sql diff --git a/backend/migrations/0006_untagged_claims_index.sql b/backend/migrations/0006_untagged_claims_index.sql new file mode 100644 index 0000000..6040582 --- /dev/null +++ b/backend/migrations/0006_untagged_claims_index.sql @@ -0,0 +1,7 @@ +-- enrich.topics fetches the next batch of untagged claims on every iteration; without an index each batch scanned +-- all claims (over a million after the history backfill) and a run took hours, blocking the enrich queue. The +-- predicate must stay identical to the query in enrich/topics.py. Built CONCURRENTLY by hand on 2026-11-14. +CREATE INDEX IF NOT EXISTS claim_untagged_idx ON claim (id) + WHERE claim_type IN ('media_mention', 'statement', 'donation', 'side_job', 'appearance', 'meeting', 'travel', + 'money_flow', 'government_decision', 'wiki_edit', 'career') + AND NOT (data ? 'topics_tagged');