perf: eliminate full Sonarr Series + Radarr Movies library fetches
All checks were successful
Build and Push Docker Image / build (push) Successful in 40s

The poller was fetching the entire series and movie libraries on every
poll cycle (~9s each). Queue and history records already embed the full
series/movie object via includeSeries/includeMovie params.

Changes:
- Remove 'Sonarr Series' and 'Radarr Movies' timed fetches from poller
- Tag queue/history records with _instanceUrl in the poller instead
- Build seriesMap/moviesMap from embedded objects in dashboard
- Remove poll:sonarr-series and poll:radarr-movies cache keys
- Fix missing axios and config imports in dashboard
- Net result: ~18s saved per poll cycle, ~2 fewer API calls
This commit is contained in:
2026-05-16 00:05:14 +01:00
parent 6e81180175
commit b44d370b51
2 changed files with 55 additions and 44 deletions

View File

@@ -80,14 +80,6 @@ async function pollAllServices() {
return { instance: inst.id, data: { records: [] } };
})
))),
timed('Sonarr Series', () => Promise.all(sonarrInstances.map(inst =>
axios.get(`${inst.url}/api/v3/series`, {
headers: { 'X-Api-Key': inst.apiKey }
}).then(res => ({ instance: inst.id, data: res.data })).catch(err => {
console.error(`[Poller] Sonarr ${inst.id} series error:`, err.message);
return { instance: inst.id, data: [] };
})
))),
timed('Radarr Queue', () => Promise.all(radarrInstances.map(inst =>
axios.get(`${inst.url}/api/v3/queue`, {
headers: { 'X-Api-Key': inst.apiKey },
@@ -106,14 +98,6 @@ async function pollAllServices() {
return { instance: inst.id, data: { records: [] } };
})
))),
timed('Radarr Movies', () => Promise.all(radarrInstances.map(inst =>
axios.get(`${inst.url}/api/v3/movie`, {
headers: { 'X-Api-Key': inst.apiKey }
}).then(res => ({ instance: inst.id, data: res.data })).catch(err => {
console.error(`[Poller] Radarr ${inst.id} movies error:`, err.message);
return { instance: inst.id, data: [] };
})
))),
timed('Radarr Tags', () => Promise.all(radarrInstances.map(inst =>
axios.get(`${inst.url}/api/v3/tag`, {
headers: { 'X-Api-Key': inst.apiKey }
@@ -131,9 +115,9 @@ async function pollAllServices() {
const [
{ result: sabQueues }, { result: sabHistories },
{ result: sonarrTagsResults }, { result: sonarrQueues },
{ result: sonarrHistories }, { result: sonarrSeriesResults },
{ result: sonarrHistories },
{ result: radarrQueues }, { result: radarrHistories },
{ result: radarrMoviesResults }, { result: radarrTagsResults },
{ result: radarrTagsResults },
{ result: qbittorrentTorrents }
] = results;
@@ -164,28 +148,49 @@ async function pollAllServices() {
// Sonarr
cache.set('poll:sonarr-tags', sonarrTagsResults, cacheTTL);
// Tag queue/history records with _instanceUrl so embedded series/movie objects can build links
cache.set('poll:sonarr-queue', {
records: sonarrQueues.flatMap(q => q.data.records || [])
records: sonarrQueues.flatMap(q => {
const inst = sonarrInstances.find(i => i.id === q.instance);
const url = inst ? inst.url : null;
return (q.data.records || []).map(r => {
if (r.series) r.series._instanceUrl = url;
return r;
});
})
}, cacheTTL);
cache.set('poll:sonarr-history', {
records: sonarrHistories.flatMap(h => h.data.records || [])
records: sonarrHistories.flatMap(h => {
const inst = sonarrInstances.find(i => i.id === h.instance);
const url = inst ? inst.url : null;
return (h.data.records || []).map(r => {
if (r.series) r.series._instanceUrl = url;
return r;
});
})
}, cacheTTL);
cache.set('poll:sonarr-series', sonarrSeriesResults.flatMap(s => {
const inst = sonarrInstances.find(i => i.id === s.instance);
return (s.data || []).map(item => ({ ...item, _instanceUrl: inst ? inst.url : null }));
}), cacheTTL);
// Radarr
cache.set('poll:radarr-queue', {
records: radarrQueues.flatMap(q => q.data.records || [])
records: radarrQueues.flatMap(q => {
const inst = radarrInstances.find(i => i.id === q.instance);
const url = inst ? inst.url : null;
return (q.data.records || []).map(r => {
if (r.movie) r.movie._instanceUrl = url;
return r;
});
})
}, cacheTTL);
cache.set('poll:radarr-history', {
records: radarrHistories.flatMap(h => h.data.records || [])
records: radarrHistories.flatMap(h => {
const inst = radarrInstances.find(i => i.id === h.instance);
const url = inst ? inst.url : null;
return (h.data.records || []).map(r => {
if (r.movie) r.movie._instanceUrl = url;
return r;
});
})
}, cacheTTL);
cache.set('poll:radarr-movies', radarrMoviesResults.flatMap(m => {
const inst = radarrInstances.find(i => i.id === m.instance);
return (m.data || []).map(item => ({ ...item, _instanceUrl: inst ? inst.url : null }));
}), cacheTTL);
cache.set('poll:radarr-tags', radarrTagsResults.flatMap(t => t.data || []), cacheTTL);
// qBittorrent