store: Fix: eliminate redundant double-query pattern in Peewee get_or_none + get_by_id
This commit is contained in:
parent
44ef789063
commit
a9e9352731
@ -0,0 +1,43 @@
|
||||
---
|
||||
id: 802b350e-296c-448a-9f76-8684e786b3b3
|
||||
type: fix
|
||||
title: "Fix: eliminate redundant double-query pattern in Peewee get_or_none + get_by_id"
|
||||
tags: [paper-dynasty-database, python, peewee, performance, fix, sqlite, fastapi]
|
||||
importance: 0.55
|
||||
confidence: 0.8
|
||||
created: "2026-03-04T03:03:30.726372+00:00"
|
||||
updated: "2026-03-04T03:03:30.726372+00:00"
|
||||
---
|
||||
|
||||
## Problem
|
||||
|
||||
`get_one_play` in `app/routers_v2/stratplays.py` made two DB round-trips for one record:
|
||||
1. `StratPlay.get_or_none(...)` — existence check, result discarded
|
||||
2. `StratPlay.get_by_id(play_id)` — fetch same record again
|
||||
|
||||
## Fix
|
||||
|
||||
Store the `get_or_none` result and reuse it directly:
|
||||
|
||||
```python
|
||||
# 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`
|
||||
Loading…
Reference in New Issue
Block a user