fix: cap event buffer and replay only recent messages on dashboard connect

data.msgs grew without bound (eventlog appended forever, also persisted in
the pickle), and ws.py replayed the entire history to every dashboard
client on connect - one JSON frame per message - making page reloads
progressively sluggish. Cap the buffer in eventlog() (configurable via
msg_buffer_size, default 500) and slice the WebSocket replay to the last
30, matching the window the HTTP render already uses.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-26 11:37:40 -04:00
co-authored by Claude Opus 4.8
parent 356c77b0b8
commit 731545dd0e
2 changed files with 6 additions and 1 deletions
+5
View File
@@ -114,6 +114,11 @@ def eventlog(host, lvl, m, service=None):
"message": m,
}
data.msgs.append(msg)
# Cap the in-memory buffer so it doesn't grow without bound; this list is
# replayed to every dashboard client on connect and persisted in the pickle.
cap = _config.get("msg_buffer_size", 500)
if cap and len(data.msgs) > cap:
del data.msgs[:-cap]
s = f"{time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(ts))} {lvl} "
if host:
s += f"{host} "
+1 -1
View File
@@ -90,7 +90,7 @@ async def handler(request):
# the client knows to append rather than prepend).
if data.msgs:
try:
for m in reversed(data.msgs):
for m in reversed(data.msgs[-30:]):
host_name = m.get("host") if isinstance(m, dict) else None
if not host_name or _user_can_see_host(user, host_name):
await ws.send_str(json.dumps({"type": "message", "data": m, "history": True}))