Batch Paperdex lookups to avoid N+1 queries in player/card list endpoints #17
Labels
No Label
ai-changes-requested
ai-failed
ai-merged
ai-pr-opened
ai-reviewed
ai-reviewing
ai-reviewing
ai-working
bug
enhancement
evolution
performance
phase-0
phase-1a
phase-1b
phase-1c
phase-1d
security
tech-debt
todo
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/paper-dynasty-database#17
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
`app/routers_v2/players.py:311-314`, `490-495`, and `cards.py:121-124` — For every player/card, a separate `Paperdex.select().where()` is issued. 500 players = 500 extra queries.
Priority: high
PR opened: #53
Fix approach: Before each result loop, collect all player IDs and issue a single
Paperdex.select().where(Paperdex.player_id << player_ids)query. Results are grouped into adict[player_id → list[row]]and looked up in O(1) per player instead of issuing a query per player.Three locations fixed:
players.py(get_players withinc_dexflag),players.py(players-by-team endpoint), andcards.py(card list endpoint). The cards endpoint also avoids a duplicatecount()query by materializing the queryset once withlist().Note: the original
cards.pycode passed aCardinstance toPaperdex.player ==(a FK toPlayer), which would have matched by Card ID rather than player ID — likely a pre-existing bug. The batched version correctly usesx.player_id.