2.2 KiB
2.2 KiB
| id | type | title | tags | importance | confidence | created | updated | relations | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| c98ad146-a578-430b-af4e-2ecda68361f1 | workflow | PR review: paper-dynasty-database#53 — batch Paperdex N+1 fix (APPROVED) |
|
0.6 | 0.8 | 2026-03-04T03:50:20.621207+00:00 | 2026-03-04T03:50:21.087536+00:00 |
|
Review Summary
PR #53 — fix: batch Paperdex lookups to avoid N+1 queries (#17) Verdict: APPROVED (posted as COMMENT — Gitea blocks self-approval)
Files Reviewed
app/routers_v2/players.pyapp/routers_v2/cards.py
Key Findings
Correctness — all good:
- Batch logic correct in all 3 locations:
Paperdex.player_id << player_idswithdex_by_playerdict grouping - Bonus bug fix: original
cards.pyhadPaperdex.player == xwherexis aCard— Peewee resolves this toCard.id(wrong), notCard.player_id. Batched version usesx.player_id(correct) - Count optimization:
len(card_list)replacesall_cards.count()saving aSELECT COUNT(*)per request inc_dexguard preserved correctly inget_players
Security: No issues. player_ids from ORM objects, not raw user input.
Suggestions (non-blocking):
- PR description says "Players-by-team endpoint" but diff actually patches
get_random_player - SQLite IN-clause limit (999 params) could theoretically be hit on unbounded
get_cardscalls list(all_cards)materializes all cards — fine trade-off, butlimitparam should be used
Pattern Notes
- Peewee
ForeignKeyFieldcomparison:Model.fk == other_model_instanceresolves toother_model_instance.pk— can be a subtle bug when types don't match - Batch pattern:
dict.setdefault(key, []).append(val)for grouping FK rows is clean and idiomatic