diff --git a/graph/workflows/pr-review-paper-dynasty-database45-batch-battingcardbattingc-712560.md b/graph/workflows/pr-review-paper-dynasty-database45-batch-battingcardbattingc-712560.md new file mode 100644 index 00000000000..ed1884bca98 --- /dev/null +++ b/graph/workflows/pr-review-paper-dynasty-database45-batch-battingcardbattingc-712560.md @@ -0,0 +1,32 @@ +--- +id: 71256008-18b8-4206-a036-909fe11ce901 +type: workflow +title: "PR review: paper-dynasty-database#45 — batch BattingCard/BattingCardRatings lookups (APPROVED)" +tags: [pr-reviewer, paper-dynasty-database, python, peewee, performance, batch-query, sqlite] +importance: 0.4 +confidence: 0.8 +created: "2026-03-03T23:48:28.060018+00:00" +updated: "2026-03-03T23:48:28.060018+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 all `BattingCard` rows for `legal_players ∪ backup_players` in one query +- Batch-fetches all `BattingCardRatings` for 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.id` in 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