fix(phase26): batch geocode endpoint for faster server trip scrubber

This commit is contained in:
Mathieu Moran
2026-08-11 04:44:37 -04:00
parent bdc7a9afb7
commit 5018c6c531
3 changed files with 64 additions and 19 deletions
+24
View File
@@ -566,6 +566,30 @@ def geocode():
return jsonify(name=None), 204
@app.post("/api/geocode/batch")
@require_login
def geocode_batch():
"""Batch geocode — returns {key: label} for all unique coords in one request."""
body = request.get_json(silent=True) or {}
coords = body.get("coords")
if not isinstance(coords, list) or not coords:
return jsonify(error="expected {coords: [{lat, lon}, ...]}"), 400
result = {}
for item in coords:
try:
lat = float(item["lat"])
lon = float(item["lon"])
except (KeyError, ValueError, TypeError):
continue
lat4 = int(round(lat, 4) * 10000)
lon4 = int(round(lon, 4) * 10000)
key = f"{lat:.3f},{lon:.3f}"
name = _geocode_cached(lat4, lon4)
if name:
result[key] = name
return jsonify(result)
# ── Uplink trigger (recompute trips after new batch) ──────────────────────
@app.post("/api/v1/portal/recompute-trips")