fix: SSE-driven chart/sparkline refresh, debounced server-side partials

This commit is contained in:
M1
2026-03-16 21:21:56 +04:00
parent 2f7273604b
commit 5071e340c7
3 changed files with 54 additions and 11 deletions
+15 -10
View File
@@ -304,6 +304,9 @@
while (bar.children.length > 60) bar.removeChild(bar.lastChild);
}
// Refresh latency chart (debounced)
scheduleChartRefresh();
// Ping table — prepend plain HTML row
const tbody = document.getElementById('pings-table');
if (tbody) {
@@ -321,16 +324,18 @@
}
});
// Poll every 30s to refresh the latency chart from server
setInterval(async () => {
try {
const res = await fetch(`/dashboard/monitors/${monitorId}/chart`, { credentials: 'same-origin' });
if (res.ok) {
const html = await res.text();
document.getElementById('latency-chart').innerHTML = html;
}
} catch {}
}, 30000);
// Refresh latency chart from server (debounced — at most once per 5s)
let _chartRefreshTimer = null;
function scheduleChartRefresh() {
if (_chartRefreshTimer) return;
_chartRefreshTimer = setTimeout(async () => {
_chartRefreshTimer = null;
try {
const res = await fetch(`/dashboard/monitors/${monitorId}/chart`, { credentials: 'same-origin' });
if (res.ok) document.getElementById('latency-chart').innerHTML = await res.text();
} catch {}
}, 5000);
}
</script>
<%~ include('./partials/foot') %>