refactor: single account-level SSE stream instead of per-monitor connections

This commit is contained in:
M1
2026-03-17 07:06:09 +04:00
parent 55f9f6d8ed
commit 66b368453d
4 changed files with 32 additions and 35 deletions
+3 -2
View File
@@ -265,9 +265,10 @@
}
});
// SSE: on each ping, refresh the chart (debounced — at most once per 5s)
// SSE: account stream filtered to this monitor — refresh chart on ping
let _chartRefreshTimer = null;
watchMonitor(monitorId, () => {
watchAccount((ping) => {
if (ping.monitor_id !== monitorId) return;
if (_chartRefreshTimer) return;
_chartRefreshTimer = setTimeout(async () => {
_chartRefreshTimer = null;
+6 -7
View File
@@ -88,13 +88,12 @@
}, 5000);
}
// SSE: subscribe to all monitors, refresh sparkline on each ping
document.querySelectorAll('[data-monitor-id]').forEach(card => {
const mid = card.dataset.monitorId;
watchMonitor(mid, () => {
const sparkEl = card.querySelector('.stat-sparkline');
if (sparkEl) scheduleSparklineRefresh(mid, sparkEl);
});
// SSE: single account stream — refresh sparkline for the relevant card on each ping
watchAccount((ping) => {
const card = document.querySelector(`[data-monitor-id="${ping.monitor_id}"]`);
if (!card) return;
const sparkEl = card.querySelector('.stat-sparkline');
if (sparkEl) scheduleSparklineRefresh(ping.monitor_id, sparkEl);
});
</script>