Expand description
Engagement WebSocket — GET /__cms__/ws (an HTTP upgrade, so it
bypasses both the page cache and CSRF).
The socket’s lifetime is the engagement signal: on connect we bump
the per-tenant “active now” gauge and start a timer; on disconnect we
decrement the gauge and append one engagement row with the measured
duration + max scroll depth. The client pushes {"scroll":N} updates
over the socket; a 30s keepalive ping detects dead connections.
Pool safety: we clone the cheap Pool handle and drop the Tenant
extractor before the socket future runs, so a Postgres-eager
checked-out connection is never held for the (long) socket lifetime —
the engagement INSERT acquires a connection only transiently at close.