OSM: Overpass-Fetch non-blocking — Antwort sofort, Kacheln im Hintergrund
Stale-Tile-Fetches blockierten den HTTP-Request minutenlang → _overpassActive blieb auf true → Frontend-Scan konnte nicht neu starten. Fix: BackgroundTasks statt await — /pois antwortet sofort mit DB-Daten, Overpass-Fetch läuft im Hintergrund. Beim nächsten Kartenschwenk sind die frisch gecachten Tiles dann verfügbar.
This commit is contained in:
parent
163b942ea4
commit
8cc528350d
1 changed files with 8 additions and 4 deletions
|
|
@ -156,8 +156,8 @@ async def _fetch_and_store_tile(poi_type, x, y):
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# GET /pois — OSM + Community-Pins
|
# GET /pois — OSM + Community-Pins
|
||||||
# fast=true: nur DB, kein Overpass-Fetch (sofortantwort)
|
# Gibt sofort DB-Daten zurück. Stale Tiles werden im Hintergrund
|
||||||
# fast=false (default): fetcht Overpass wenn Tiles veraltet sind
|
# nachgeladen — beim nächsten Scan des gleichen Bereichs sind sie frisch.
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
@router.get('/pois')
|
@router.get('/pois')
|
||||||
async def get_pois(
|
async def get_pois(
|
||||||
|
|
@ -167,6 +167,7 @@ async def get_pois(
|
||||||
north: float = Query(...),
|
north: float = Query(...),
|
||||||
east: float = Query(...),
|
east: float = Query(...),
|
||||||
fast: bool = Query(False),
|
fast: bool = Query(False),
|
||||||
|
background_tasks: BackgroundTasks = None,
|
||||||
user = Depends(get_optional_user),
|
user = Depends(get_optional_user),
|
||||||
):
|
):
|
||||||
result = []
|
result = []
|
||||||
|
|
@ -177,8 +178,11 @@ async def get_pois(
|
||||||
stale = _stale_tiles(type, tiles)
|
stale = _stale_tiles(type, tiles)
|
||||||
|
|
||||||
if stale and not fast:
|
if stale and not fast:
|
||||||
await asyncio.gather(*[_fetch_and_store_tile(type, x, y) for (x, y) in stale])
|
# Hintergrund-Fetch: Antwort kommt sofort, Overpass lädt asynchron
|
||||||
fetched_fresh = True
|
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:
|
with db() as conn:
|
||||||
reported = {
|
reported = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue