1.8 KiB
1.8 KiB
| id | type | title | tags | importance | confidence | created | updated | relations | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 802b350e-296c-448a-9f76-8684e786b3b3 | fix | Fix: eliminate redundant double-query pattern in Peewee get_or_none + get_by_id |
|
0.55 | 0.8 | 2026-03-04T03:03:30.726372+00:00 | 2026-03-04T03:03:31.389474+00:00 |
|
Problem
get_one_play in app/routers_v2/stratplays.py made two DB round-trips for one record:
StratPlay.get_or_none(...)— existence check, result discardedStratPlay.get_by_id(play_id)— fetch same record again
Fix
Store the get_or_none result and reuse it directly:
# Before
if StratPlay.get_or_none(StratPlay.id == play_id) is None:
raise HTTPException(status_code=404, detail=f"Play ID {play_id} not found")
r_play = model_to_dict(StratPlay.get_by_id(play_id))
return r_play
# After
play = StratPlay.get_or_none(StratPlay.id == play_id)
if play is None:
raise HTTPException(status_code=404, detail=f"Play ID {play_id} not found")
return model_to_dict(play)
Files Changed
app/routers_v2/stratplays.py(lines ~1405-1409)
Notes
- Linter (ruff/black) auto-reformats unrelated code when editing this file — apply fix via Python string replace to avoid cosmetic diffs
- PR #52 merged into
next-release