fix: fetch sparkline/chart immediately on SSE ping, no debounce delay

This commit is contained in:
M1
2026-03-17 07:12:48 +04:00
parent b802c7c68b
commit 94d24bac35
2 changed files with 20 additions and 28 deletions
+10 -12
View File
@@ -265,18 +265,16 @@
}
});
// SSE: account stream filtered to this monitor — refresh chart on ping
let _chartRefreshTimer = null;
watchAccount((ping) => {
if (ping.monitor_id !== monitorId) return;
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);
// SSE: on ping for this monitor, fetch fresh chart
let _fetchingChart = false;
watchAccount(async (ping) => {
if (ping.monitor_id !== monitorId || _fetchingChart) return;
_fetchingChart = true;
try {
const res = await fetch(`/dashboard/monitors/${monitorId}/chart`, { credentials: 'same-origin' });
if (res.ok) document.getElementById('latency-chart').innerHTML = await res.text();
} catch {}
_fetchingChart = false;
});
</script>