From 731545dd0e97f8e093a9c786a8956db4ff9aec1c Mon Sep 17 00:00:00 2001 From: Andreas Wrede Date: Fri, 26 Jun 2026 11:37:40 -0400 Subject: [PATCH] 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 --- hbd/server/notify.py | 5 +++++ hbd/server/ws.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/hbd/server/notify.py b/hbd/server/notify.py index be5bf61..4cc6655 100644 --- a/hbd/server/notify.py +++ b/hbd/server/notify.py @@ -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} " diff --git a/hbd/server/ws.py b/hbd/server/ws.py index f8f9d6c..1128203 100644 --- a/hbd/server/ws.py +++ b/hbd/server/ws.py @@ -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}))