-- Per-manga sync-state derivation joins crawler_jobs to manga_sources via -- (payload->>'source_id', payload->>'source_manga_key') for the -- `sync_manga` job kind (whose payload doesn't carry a manga_id directly). -- Without this index the join falls back to a seqscan of crawler_jobs on -- every admin manga listing — a noticeable cost as the job table grows -- with the daily metadata pass. -- -- Partial on `state IN ('pending','running')` so it covers only in-flight -- jobs (the bulk of the table is done/dead and irrelevant to "is this -- manga being synced right now"). CREATE INDEX crawler_jobs_sync_manga_key_idx ON crawler_jobs ((payload->>'source_manga_key')) WHERE state IN ('pending', 'running') AND payload->>'kind' = 'sync_manga';