From 90dc9c065a61424cf4ba9eca07c4d90800f0f05d Mon Sep 17 00:00:00 2001 From: farzad Date: Thu, 5 Feb 2026 00:15:24 -0800 Subject: [PATCH] Enhance data fetching in visualizer/main.js to prevent duplicate requests - Introduced a flag to track ongoing fetch requests, preventing multiple simultaneous calls to the API. - The problem of retry storm can happen if the data is large or the bandwidth is limited. fetchAndRender does not finish before the next interval and a buildup of requests will happen. --- scripts/static/js/main.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scripts/static/js/main.js b/scripts/static/js/main.js index 46f09abbb..2d2db3985 100644 --- a/scripts/static/js/main.js +++ b/scripts/static/js/main.js @@ -118,7 +118,12 @@ function loadAndRenderData(data) { if (window.STATIC_DATA) { loadAndRenderData(window.STATIC_DATA); } else { + let isFetching = false; + function fetchAndRender() { + if (isFetching) return; + isFetching = true; + fetch('/api/data') .then(resp => resp.json()) .then(data => { @@ -128,6 +133,12 @@ if (window.STATIC_DATA) { } lastDataStr = dataStr; loadAndRenderData(data); + }) + .catch(err => { + console.error('Failed to fetch data:', err); + }) + .finally(() => { + isFetching = false; }); } fetchAndRender();