From 937f3094c652e14e142d22b7f40efd091698f944 Mon Sep 17 00:00:00 2001 From: BoulderBadgeDad Date: Fri, 19 Jun 2026 17:28:45 -0700 Subject: [PATCH] video Downloads page: stop polling when off-page (incl. music side); 2s cadence MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The active-downloads poll kept running in the background — the page-change event that stops it only fires for video-side navigations, not when switching to the music side, so /api/video/downloads/active was being hit forever. poll() now bails (and clears the timer) whenever the Downloads page isn't on screen (data-side!=video or the subpage is hidden). Also matched the music page's 2s active cadence (6s idle). Still HTTP polling, same as the music downloads page (which polls /api/downloads/all every 2s — the app's SocketIO is for other realtime, not the downloads list). --- webui/static/video/video-downloads-page.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/webui/static/video/video-downloads-page.js b/webui/static/video/video-downloads-page.js index d58a0620..7005990c 100644 --- a/webui/static/video/video-downloads-page.js +++ b/webui/static/video/video-downloads-page.js @@ -189,8 +189,17 @@ function anyActive() { return !!document.querySelector('.adl-row.adl-row-active, .adl-row.adl-row-queued'); } - function poll() { getJSON(URL_ACTIVE).then(function (d) { if (d) render(d.downloads || []); schedule(); }); } - function schedule() { if (_timer) clearTimeout(_timer); _timer = setTimeout(poll, anyActive() ? 1500 : 6000); } + // Only poll while the Downloads page is actually on screen — not in the background + // and not after switching to the music side (where the page-change event never fires). + function _onPage() { + return document.body.getAttribute('data-side') === 'video' && + !!document.querySelector('[data-video-subpage="video-downloads"]:not([hidden])'); + } + function poll() { + if (!_onPage()) { stop(); return; } + getJSON(URL_ACTIVE).then(function (d) { if (d) render(d.downloads || []); schedule(); }); + } + function schedule() { if (_timer) clearTimeout(_timer); _timer = setTimeout(poll, anyActive() ? 2000 : 6000); } function start() { wire(); if (_timer) clearTimeout(_timer); poll(); } function stop() { if (_timer) { clearTimeout(_timer); _timer = null; } }