Pre-seed McDonald's locations + smart proximity endpoint #20
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
todo-mcd-preseed-locations+todo-mcd-smart-proximity(lightweight work, no plan phase)Repo
forgejo_admin/mcd-tracker-apiUser Story
As a user tapping "Near Me"
I want to see nearby McDonald's instantly
So that I don't wait for a flaky external API that times out
Context
The
/locations/nearbyendpoint currently calls the Overpass API (OpenStreetMap) in real-time for every request. Overpass is a free public service that rate-limits and times out frequently — we're seeing 504s on 25km radius queries, which surface as 503s to the user.McDonald's locations are essentially static (~13k in the US, change rate: a few dozen per year). Querying a live external API for static data on every request is architecturally wrong.
Decision: pre-seed McDonald's locations into Postgres and query locally. Overpass becomes a seed/refresh tool, never called at runtime.
The
haversine_distancefunction already exists inservices/geo.py. The_find_saved_matchlogic inroutes/nearby.pyalready cross-references OSM results with user's saved locations — this stays, just reads from Postgres instead of Overpass.File Targets
Files to create:
src/mcd_tracker_api/models.py— addMcDonaldsLocationmodel (osm_id, name, address, city, state, lat, lng)alembic/versions/xxx_add_mcdonalds_locations.py— migration for the new tablesrc/mcd_tracker_api/scripts/seed_locations.py— one-time batch Overpass query, upsert into PostgresFiles to modify:
src/mcd_tracker_api/routes/nearby.py— refactor to querymcdonalds_locationstable instead of calling Overpass at runtime. KeepNearbyResponseschema unchanged so frontend doesn't break.src/mcd_tracker_api/services/overpass.py— keep as-is (used by seed script only, no longer imported by routes)Files NOT to touch:
src/mcd_tracker_api/routes/locations.py— saved locations logic is separatesrc/mcd_tracker_api/routes/codes.py— unrelatedAcceptance Criteria
mcdonalds_locationstable exists with osm_id unique index and lat/lng columnsGET /locations/nearby?lat=X&lng=Y&radius=Nreturns locations from Postgres, sorted by distanceNearbyResponsewithNearbyLocationitems)Test Expectations
/locations/nearbyreturns locations sorted by distance from seeded datapytest tests/ -vConstraints
routes/nearby.pyhaversine_distancefromservices/geo.py— don't add PostGISservices/overpass.py(may need a wider-radius query function)NearbyResponseandNearbyLocationschemas unchangedChecklist
Related
project-mcd-tracker— project this affectstodo-mcd-preseed-locations— pal-e-docs TODOtodo-mcd-smart-proximity— pal-e-docs TODOservices/geo.py— existing haversine functionservices/overpass.py— existing Overpass client (becomes seed-only)