perf(pipeline): in-memory cache for usv_track (warm: 20ms vs 1.8s cold)
This commit is contained in:
@@ -201,9 +201,14 @@ def _read_usv_track(nav_log_path: Path, max_pts: int = 2000) -> list[dict]:
|
||||
return pts
|
||||
|
||||
|
||||
_track_cache: dict[str, list[dict]] = {}
|
||||
|
||||
|
||||
@app.get("/sorties/{sortie_id:path}/usv_track")
|
||||
async def get_usv_track(sortie_id: str):
|
||||
"""Return USV GPS track [{t_ms, lat, lon, heading, source}] for map polylines."""
|
||||
if sortie_id in _track_cache:
|
||||
return JSONResponse(_track_cache[sortie_id])
|
||||
raw_dir = OUTPUT_DIR / sortie_id / "raw"
|
||||
nav_logs = list(raw_dir.rglob("*_navigation_log.csv")) if raw_dir.exists() else []
|
||||
if not nav_logs:
|
||||
@@ -212,4 +217,5 @@ async def get_usv_track(sortie_id: str):
|
||||
for nav_log in nav_logs:
|
||||
pts.extend(await asyncio.to_thread(_read_usv_track, nav_log))
|
||||
pts.sort(key=lambda p: p["t_ms"])
|
||||
_track_cache[sortie_id] = pts
|
||||
return JSONResponse(pts)
|
||||
|
||||
Reference in New Issue
Block a user