perf: pause polling intervals when browser tab is hidden
- Replace raw setInterval with startPolling/stopPolling functions - Add visibilitychange listener to pause when tab is hidden - Immediately refresh data when tab becomes visible again - Saves bandwidth and CPU when the dashboard is in background
This commit is contained in:
@@ -1908,10 +1908,33 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
}, { passive: false });
|
||||
}
|
||||
|
||||
// Set up periodic updates
|
||||
setInterval(loadStatus, 10000);
|
||||
setInterval(loadLogs, 5000);
|
||||
setInterval(loadActiveArguments, 5000); // Refresh active arguments
|
||||
// Set up periodic updates with visibility-aware polling
|
||||
let statusInterval, logsInterval, argsInterval;
|
||||
|
||||
function startPolling() {
|
||||
if (!statusInterval) statusInterval = setInterval(loadStatus, 10000);
|
||||
if (!logsInterval) logsInterval = setInterval(loadLogs, 5000);
|
||||
if (!argsInterval) argsInterval = setInterval(loadActiveArguments, 5000);
|
||||
}
|
||||
|
||||
function stopPolling() {
|
||||
clearInterval(statusInterval); statusInterval = null;
|
||||
clearInterval(logsInterval); logsInterval = null;
|
||||
clearInterval(argsInterval); argsInterval = null;
|
||||
}
|
||||
|
||||
document.addEventListener('visibilitychange', () => {
|
||||
if (document.hidden) {
|
||||
stopPolling();
|
||||
console.log('⏸ Tab hidden — polling paused');
|
||||
} else {
|
||||
loadStatus(); loadLogs(); loadActiveArguments();
|
||||
startPolling();
|
||||
console.log('▶️ Tab visible — polling resumed');
|
||||
}
|
||||
});
|
||||
|
||||
startPolling();
|
||||
});
|
||||
|
||||
// Utility functions
|
||||
|
||||
Reference in New Issue
Block a user