2.1 KiB
2.1 KiB
| id | type | title | tags | importance | confidence | created | updated | relations | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 71256008-18b8-4206-a036-909fe11ce901 | workflow | PR review: paper-dynasty-database#45 — batch BattingCard/BattingCardRatings lookups (APPROVED) |
|
0.4 | 0.8 | 2026-03-03T23:48:28.060018+00:00 | 2026-03-03T23:48:28.467508+00:00 |
|
PR #45 — fix: batch BattingCard/BattingCardRatings lookups in lineup builder
Verdict: APPROVED (could not post — Gitea blocks self-review)
Files reviewed: app/routers_v2/teams.py
What the PR does:
- Before the position loop in
get_team_lineup, batch-fetches allBattingCardrows forlegal_players ∪ backup_playersin one query - Batch-fetches all
BattingCardRatingsfor those cards in a second query - Builds
_batting_cards_by_player(player_id → BattingCard) and_ratings_by_card_hand(card_id → {hand → BattingCardRatings}) dicts - Rewrites
get_bratings()closure to do O(1) dict lookups instead of 3 DB queries per player
Key correctness checks:
- Dict keys match:
battingcard_id(FK integer) in ratings dict ==this_bcard.idin lookup - Error behaviour preserved: missing card/ratings still raises AttributeError (caught by callers)
- Empty guard:
if _batting_cards_by_player else []prevents empty IN clause - Passing BattingCard model instances to Peewee
<<is valid; PK extraction is automatic
Pre-existing issues noted (out of scope):
- Dead code block lines 544-576 (old batch approach, commented out)
get_bratings()call at line 537 not wrapped in try/except