fix(vessels): protect Hormuz VesselAPI rows from AISStream eviction

AISStream's live US-coast feed crowds vessel_last_known past _MAX_VESSELS
(6000) and the 'evict oldest seen_at' pass reaps the Hormuz VesselAPI rows,
which are only refreshed every VESSELAPI_INTERVAL (~4.8h). Result: the poller
was fetching 50 Hormuz vessels per 2xx but /api/vessels?bbox=Hormuz stayed
empty. Eviction now skips src=vesselapi rows (falls back to evictable-only,
clamped) so the blind-spot box stays resident between polls.
This commit is contained in:
Sirius DevOps 2026-08-29 13:05:57 -04:00
commit 86b412dd37
2 changed files with 45 additions and 1 deletions

View file

@ -993,8 +993,18 @@ async def upsert_vessel(marker: dict) -> None:
vessel_last_known[vid] = stored
if len(vessel_last_known) > _MAX_VESSELS:
excess = len(vessel_last_known) - int(_MAX_VESSELS * 0.9)
# AISStream's live US-coast feed can crowd the shared store past
# _MAX_VESSELS and evict the Hormuz VesselAPI rows (refreshed only
# every VESSELAPI_INTERVAL) as "oldest". Keep src=vesselapi rows
# resident so the blind-spot box stays visible between polls.
evictable = [
k for k, v in vessel_last_known.items()
if (v.get("extra") or {}).get("src") != "vesselapi"
]
if len(evictable) < excess:
excess = len(evictable)
oldest = sorted(
vessel_last_known,
evictable,
key=lambda k: vessel_last_known[k].get("seen_at", ""),
)[:excess]
for k in oldest: