fix: evict oldest chart runs as a group instead of individual pings

This commit is contained in:
nate 2026-03-18 20:00:11 +04:00
parent 993e6bb1df
commit 766d1094ad
1 changed files with 12 additions and 2 deletions

View File

@ -465,13 +465,23 @@
while (tbody.children.length > 100) tbody.removeChild(tbody.lastChild); while (tbody.children.length > 100) tbody.removeChild(tbody.lastChild);
} }
// Chart — push new ping and re-render locally // Chart — push new ping, evict oldest complete runs to cap at ~50 runs
chartPings.push({ chartPings.push({
latency_ms: ping.latency_ms, region: ping.region || '__none__', latency_ms: ping.latency_ms, region: ping.region || '__none__',
checked_at: ping.checked_at, up: ping.up, run_id: ping.run_id || null, checked_at: ping.checked_at, up: ping.up, run_id: ping.run_id || null,
status_code: ping.status_code status_code: ping.status_code
}); });
if (chartPings.length > 200) chartPings.shift(); // Count distinct runs and remove oldest runs as a group
const MAX_RUNS = 50;
const seen = []; const runSet = new Set();
for (const p of chartPings) {
const rid = p.run_id || p.checked_at;
if (!runSet.has(rid)) { runSet.add(rid); seen.push(rid); }
}
if (seen.length > MAX_RUNS) {
const stale = new Set(seen.slice(0, seen.length - MAX_RUNS));
chartPings = chartPings.filter(p => !stale.has(p.run_id || p.checked_at));
}
renderChart(); renderChart();
}); });
</script> </script>