claude-memory/graph/fixes/fix-eliminate-redundant-double-query-pattern-in-peewee-get-o-802b35.md

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
paper-dynasty-database
python
peewee
performance
fix
sqlite
fastapi
0.55 0.8 2026-03-04T03:03:30.726372+00:00 2026-03-04T03:03:31.389474+00:00
target type direction strength edge_id
04e57a23-0a20-49d6-8c5a-2fa5fc4e55b5 RELATED_TO outgoing 0.79 d1610aeb-7f7f-4d7d-9911-b32a5e2fbd7c
target type direction strength edge_id
d36a86f0-8183-4c94-8d63-0be65d3fd63a RELATED_TO outgoing 0.75 30ef8743-65a7-423d-9867-f9949c88bb8d
target type direction strength edge_id
5ae1bf6e-1e1c-4486-8a4d-10afd9e42189 RELATED_TO outgoing 0.75 57e15307-bbd9-4314-b62e-5a042db329ce

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:

# 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