oliver-zehentleitner / maity

hub: claim_request: drop the unused (status, lapses_at) index; index what the minute sweep reads

Sign in to report

tsk-6yzyabwt7vb5 Proposed

Audit round 6 (tsk-hgnbapyw7hnh), read at 046a4d3b. Kind: debt (an unused index, a full scan on a timer).

What is wrong

  • ix_claim_request_status_lapses (status, lapses_at) (tables.py:2101, migration 20261126090000_outside_claims.py:86) serves no query: the only filter on claim_request.status is in declined_on (claim_requests.py:568), which is led by the member.
  • claim_requests.sweep runs every minute with WHERE pending IS TRUE ORDER BY requested_at, id (claim_requests.py:1209-1211). The only index holding pending is the unique key on (task_id, pending), so the sweep scans the whole table, and settled rows are kept forever. The per-project reads (:151, :426, :1158) have the same shape.

Proposal

  • One migration: drop ix_claim_request_status_lapses, add an index the sweep and the per-project reads can use (e.g. (pending, requested_at) or (project_id, pending)), or move those reads to status = pending with an index led by status.

Effort / risk: S. Low; one migration, model and migration kept equal by test_schema.