perf: batch image_url prefetch in list_card_states to eliminate N+1 (#199) #206

Merged
cal merged 1 commits from issue/199-perf-n-1-query-in-build-card-state-response-for-im into main 2026-04-08 02:25:53 +00:00

1 Commits

Author SHA1 Message Date
Cal Corum
b7196c1c56 perf: batch image_url prefetch in list_card_states to eliminate N+1 (#199)
Replace per-row CardModel.get() in _build_card_state_response with a
bulk prefetch in list_card_states: collect variant player IDs, issue at
most 2 queries (BattingCard + PitchingCard), build a (player_id, variant)
-> image_url map, and pass the resolved value directly to the helper.

The single-card get_card_state path is unchanged and still resolves
image_url inline (one extra query is acceptable for a single-item response).

Closes #199

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-07 21:04:33 -05:00