mirror of
https://github.com/gadgethd/ukmesh.git
synced 2026-09-09 16:45:33 +00:00
The cold WS initial-state fetch (fetchInitialState -> getRecentPackets + getRecentMessages) called meshcore_canonical_node_id() ~100k times per fetch (per-row subquery against node_identity_aliases). 6.97s cold on the 2-vCPU box; under load it exceeded the 8s WS_INITIAL_STATE_DB_TIMEOUT_MS abort, so the map never received an initial snapshot (empty map + synthetic_check_failed). Replace the per-row function calls with node_identity_aliases LEFT JOINs (COALESCE(alias.canonical_node_id, upper(btrim(node_id))) - exact function semantics, table ~20 rows). Measured: full getRecentMessages 6968ms -> 1772ms (4x); getRecentPackets same pattern. Also raise the WS_INITIAL_STATE_DB_TIMEOUT_MS env cap 9s -> 60s (default stays 8s; deploy sets 30s) so slow-but-working fetches complete and warm the cache instead of aborting forever. 281/281 backend tests pass; tsc clean. Live: initial_state 502ms warm, all synthetic checks green.