Seed full US McDonald's + cache-on-miss for uncovered areas #22
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-smart-proximity(lightweight work, no plan phase)Repo
forgejo_admin/mcd-tracker-apiUser Story
As a user anywhere in the US tapping "Near Me"
I want to see nearby McDonald's instantly from a pre-seeded database
So that I never depend on a flaky external API at runtime
Context
PR #21 merged the
mcdonalds_locationstable, seed script, and refactored/locations/nearbyto query Postgres instead of Overpass. However, the seed script defaults to Denver metro (50km radius). The user is NOT in Denver.Two changes needed:
node["brand"="McDonald's"](area:US);. This is a trivial dataset for Postgres./locations/nearbyfinds no cached locations within the query radius, fall back to querying Overpass, cache the results inmcdonalds_locations, and serve them. This handles edge cases (international users, brand-new locations not yet in the monthly refresh).The cache-on-miss makes the Overpass call a first-time-only fallback, not the primary path. After the first query in any area, all subsequent queries are instant from Postgres.
Design decisions:
created_aton cached rows. If oldest row in the area is >30 days, refresh from Overpass in backgroundFile Targets
Files to modify:
src/mcd_tracker_api/scripts/seed_locations.py— change default from Denver 50km to full US. Add--countryflag or use area-based Overpass query. Increase timeout for larger query.src/mcd_tracker_api/routes/nearby.py— add cache-on-miss logic: if Postgres returns 0 results for the query area, call Overpass, upsert results, return them. Make this async since it may call Overpass.src/mcd_tracker_api/models.py— consider addingregion_queried_ator usingcreated_atfor cache freshnessFiles NOT to touch:
src/mcd_tracker_api/schemas.py— response schema stays the samesrc/mcd_tracker_api/services/overpass.py— already works, used by both seed script and cache-on-misssrc/mcd_tracker_api/routes/locations.py— saved locations are separateAcceptance Criteria
python -m mcd_tracker_api.scripts.seed_locationsseeds all US locations/locations/nearbyreturns cached results when available (no Overpass call)/locations/nearbyfalls back to Overpass when no cached locations exist for the area, caches the resultsmcdonalds_locationsso subsequent queries are instantNearbyResponse)Test Expectations
pytest tests/ -vConstraints
SEED_TIMEOUT = 120.0)routes/nearby.pyandscripts/seed_locations.pyChecklist
Related
project-mcd-tracker— project this affectstodo-mcd-smart-proximity— pal-e-docs TODO