CREATE INDEX IF NOT EXISTS idx_generation_tasks_active_state_check
    ON generation_tasks(updated_at DESC, id DESC)
    WHERE article_id IS NOT NULL
      AND status IN ('queued', 'running');

CREATE INDEX IF NOT EXISTS idx_generation_tasks_recent_completed_state_check
    ON generation_tasks(updated_at DESC, id DESC)
    WHERE article_id IS NOT NULL
      AND status = 'completed';
