perf: geocode pipeline — batch POST + parallel server, 200→1 roundtrip

JS preload(): replaced N individual GET /api/geocode (concurrency 2) with
a single POST /api/geocode/batch — one HTTP roundtrip instead of up to
N/2 sequential ones. schedLoc debounce reduced 600→200ms.

Server geocode_batch(): ThreadPoolExecutor(max_workers=4) parallelises
Nominatim/reverse_geocoder calls instead of sequential loop. Deduplicates
coords before submitting futures. lru_cache absorbs duplicates within batch.

Pi geocode_batch_route(): deduplicate coords, removed stale 'if label:'
guard (label always non-empty after BUG-13 fix).
This commit is contained in:
Mathieu Moran
2026-08-12 03:15:30 -04:00
parent ad10a873b4
commit e60b7d7d36
3 changed files with 54 additions and 25 deletions
+6 -3
View File
@@ -212,6 +212,9 @@ def geocode_batch_route():
coords = body.get("coords")
if not isinstance(coords, list) or not coords:
return jsonify(error="expected {coords: [{lat, lon}, ...]}"), 400
# Deduplicate — same (lat4,lon4) would hit lru_cache anyway but avoids
# submitting redundant work.
seen = set()
result = {}
for item in coords:
try:
@@ -221,9 +224,9 @@ def geocode_batch_route():
continue
lat4 = int(round(lat, 4) * 10000)
lon4 = int(round(lon, 4) * 10000)
label = _geocode_cached(lat4, lon4)
if label:
result[f"{lat:.3f},{lon:.3f}"] = label
if (lat4, lon4) not in seen:
seen.add((lat4, lon4))
result[f"{lat:.3f},{lon:.3f}"] = _geocode_cached(lat4, lon4)
return jsonify(result)
@app.route('/api/dash/devices')