perf: drastically reduce background API requests to Navidrome (v1.34.5)

- NowPlaying polling: only active while dropdown is open + respects
  Page Visibility API — was firing every 10s unconditionally (~8.6k req/day)
- Connection check interval: 30s → 120s (4× reduction)
- Queue sync debounce: 1.5s → 5s (prevents burst on rapid skip)
- Rating prefetch: add 7-minute in-memory TTL cache for artist/album
  ratings — repeated random album loads no longer re-fetch known ratings

Fixes server log flooding reported by users behind reverse proxies (Traefik).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Psychotoxical
2026-04-08 17:57:49 +02:00
parent 1e4b851e9e
commit 3643a78cd6
9 changed files with 47 additions and 20 deletions
+5 -7
View File
@@ -36,16 +36,14 @@ export default function NowPlayingDropdown() {
});
};
// Poll in background so the badge stays current without opening the dropdown
// Poll only while the dropdown is open AND the page is visible.
useEffect(() => {
if (!isOpen) return;
fetchNowPlaying();
const id = setInterval(fetchNowPlaying, 10000);
const id = setInterval(() => {
if (document.visibilityState === 'visible') fetchNowPlaying();
}, 10000);
return () => clearInterval(id);
}, []);
// Refresh immediately when dropdown is opened
useEffect(() => {
if (isOpen) fetchNowPlaying();
}, [isOpen]);
// Click outside to close