Fix N+1 query in nearby endpoint, add boundary test, fix photo media type #12
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Lineage
plan-mcd-tracker→ Phase 5c → QA audit findingsRepo
forgejo_admin/mcd-tracker-apiUser Story
auto-location: Nearby endpoint must be fast even with 20+ saved locationsArchitecture
arch-dataflow-mcd-tracker#flow-5-auto-detect-location— nearby flow should be efficientContext
Full repo audit (116 tests, 14 endpoints) found 3 issues. This PR fixes all three.
File Targets
BLOCKER: N+1 in nearby.py (lines 119-131)
src/mcd_tracker_api/routes/nearby.py—_build_slot_info()is called once per matched saved location inside the loop. With 20 OSM results and 10 matches → 10-20 extra queries.MEDIUM: Rolling window boundary test
tests/test_locations.py— add test for code expiring at exactlynow + 30 days. Query usesexpires_at > func.now()(strict inequality). Verify code at exact boundary is NOT counted as active.LOW: Photo media type
src/mcd_tracker_api/routes/receipts.py—FileResponsehardcodesmedia_type="image/jpeg"but accepts .jpg, .jpeg, .png, .webp. Fix: infer media type from file extension.Acceptance Criteria
Test Expectations
pytest tests/ -vConstraints
WHERE location_id IN (...)patternChecklist
Closes #11Related
phase-mcd-tracker-5c-gps-nearby— parent phaseplan-mcd-tracker— parent plan