feat: AIS stream follows the map viewport
All checks were successful
build-and-deploy / build (push) Successful in 2m32s
All checks were successful
build-and-deploy / build (push) Successful in 2m32s
The Vessels layer now retunes the server-side AISStream subscription to the client viewport instead of a static AISSTREAM_BBOX. The frontend POSTs its quantized viewport box to /api/vessels/subscribe on moveend; the ais_stream worker coalesces and applies it at the service's 1 subscription/s cap, then last-known positions for the new area arrive within a couple of seconds (the frontend does one follow-up fetch after retuning). Bounds the in-memory vessel store across regions. Key stays server-side.
This commit is contained in:
parent
c58f66770c
commit
32320635dc
6 changed files with 185 additions and 6 deletions
|
|
@ -66,6 +66,9 @@ _QUANT = 0.25 # degrees — pan jitter inside a cell reuses the TTL entry
|
|||
# Last-known AIS positions (MMSI -> marker). Filled by ais_stream worker.
|
||||
vessel_last_known: dict[str, dict] = {}
|
||||
vessel_lock = asyncio.Lock()
|
||||
# Viewport-following accumulates vessels across every region visited in a
|
||||
# session — keep the in-memory store bounded (oldest entries evicted).
|
||||
_MAX_VESSELS = 6000
|
||||
|
||||
|
||||
def overlay_catalog() -> dict:
|
||||
|
|
@ -620,6 +623,14 @@ async def upsert_vessel(marker: dict) -> None:
|
|||
),
|
||||
"seen_at": datetime.now(timezone.utc).isoformat(),
|
||||
}
|
||||
if len(vessel_last_known) > _MAX_VESSELS:
|
||||
excess = len(vessel_last_known) - int(_MAX_VESSELS * 0.9)
|
||||
oldest = sorted(
|
||||
vessel_last_known,
|
||||
key=lambda k: vessel_last_known[k].get("seen_at", ""),
|
||||
)[:excess]
|
||||
for k in oldest:
|
||||
vessel_last_known.pop(k, None)
|
||||
|
||||
|
||||
def _wfigs_params(bbox: str | None, *, offset_m: float = 250.0) -> dict:
|
||||
|
|
|
|||
Loading…
Reference in a new issue