Stop watchlist countdown refetch loop

- Avoid refetching /api/watchlist/count every second when no auto-run is scheduled.
- Keep the timer active only while a next run exists; otherwise leave the label static.
This commit is contained in:
Antti Kettunen 2026-05-02 10:03:28 +03:00
parent 7405d04900
commit 5ef83cea72
No known key found for this signature in database
GPG key ID: C6B2A3D250359BD7

View file

@ -1837,6 +1837,19 @@ function startWatchlistCountdownTimer(initialSeconds) {
} }
let remainingSeconds = initialSeconds; let remainingSeconds = initialSeconds;
const timerElement = document.getElementById('watchlist-next-auto-timer');
const updateTimerText = (seconds) => {
if (!timerElement) return;
const countdownText = seconds > 0 ? formatCountdownTime(seconds) : '';
timerElement.textContent = `Next Auto${countdownText ? ': ' + countdownText : ''}`;
};
// If there is no scheduled next run, don't keep polling the endpoint every second.
if (remainingSeconds <= 0) {
updateTimerText(0);
watchlistCountdownInterval = null;
return;
}
watchlistCountdownInterval = setInterval(async () => { watchlistCountdownInterval = setInterval(async () => {
remainingSeconds--; remainingSeconds--;
@ -1846,23 +1859,23 @@ function startWatchlistCountdownTimer(initialSeconds) {
try { try {
const response = await fetch('/api/watchlist/count'); const response = await fetch('/api/watchlist/count');
const data = await response.json(); const data = await response.json();
remainingSeconds = data.next_run_in_seconds || 0; const nextRunSeconds = data.next_run_in_seconds || 0;
const timerElement = document.getElementById('watchlist-next-auto-timer'); if (nextRunSeconds > 0) {
if (timerElement) { remainingSeconds = nextRunSeconds;
const countdownText = formatCountdownTime(remainingSeconds); updateTimerText(remainingSeconds);
timerElement.textContent = `Next Auto${countdownText ? ': ' + countdownText : ''}`; } else {
// No scheduled auto-run; stop polling until the page is refreshed
clearInterval(watchlistCountdownInterval);
watchlistCountdownInterval = null;
updateTimerText(0);
} }
} catch (error) { } catch (error) {
console.debug('Error updating watchlist countdown:', error); console.debug('Error updating watchlist countdown:', error);
} }
} else { } else {
// Update the display // Update the display
const timerElement = document.getElementById('watchlist-next-auto-timer'); updateTimerText(remainingSeconds);
if (timerElement) {
const countdownText = formatCountdownTime(remainingSeconds);
timerElement.textContent = `Next Auto${countdownText ? ': ' + countdownText : ''}`;
}
} }
}, 1000); // Update every second }, 1000); // Update every second
} }
@ -3791,4 +3804,3 @@ function cleanupSyncPageLogs() {
// --- Global Cleanup on Page Unload --- // --- Global Cleanup on Page Unload ---
// Note: Automatic wishlist processing now runs server-side and continues even when browser is closed // Note: Automatic wishlist processing now runs server-side and continues even when browser is closed
// =============================== // ===============================