diff --git a/backend/routes/osm.py b/backend/routes/osm.py index 2c7375b..ddec009 100644 --- a/backend/routes/osm.py +++ b/backend/routes/osm.py @@ -156,8 +156,8 @@ async def _fetch_and_store_tile(poi_type, x, y): # ------------------------------------------------------------------ # GET /pois — OSM + Community-Pins -# fast=true: nur DB, kein Overpass-Fetch (sofortantwort) -# fast=false (default): fetcht Overpass wenn Tiles veraltet sind +# Gibt sofort DB-Daten zurück. Stale Tiles werden im Hintergrund +# nachgeladen — beim nächsten Scan des gleichen Bereichs sind sie frisch. # ------------------------------------------------------------------ @router.get('/pois') async def get_pois( @@ -167,6 +167,7 @@ async def get_pois( north: float = Query(...), east: float = Query(...), fast: bool = Query(False), + background_tasks: BackgroundTasks = None, user = Depends(get_optional_user), ): result = [] @@ -177,8 +178,11 @@ async def get_pois( stale = _stale_tiles(type, tiles) if stale and not fast: - await asyncio.gather(*[_fetch_and_store_tile(type, x, y) for (x, y) in stale]) - fetched_fresh = True + # Hintergrund-Fetch: Antwort kommt sofort, Overpass lädt asynchron + async def _bg_fetch(): + for (x, y) in stale: + await _fetch_and_store_tile(type, x, y) + background_tasks.add_task(_bg_fetch) with db() as conn: reported = {