Merge pull request 'fix: full pagination + non-silent errors in PollingRadarrRetriever' (#25) from fix-radarr-retriever into develop-merge
Build and Push Docker Image / build (push) Has been cancelled
CI / Security audit (push) Has been cancelled
CI / Tests & coverage (push) Has been cancelled
Licence Check / Licence compatibility and copyright header verification (push) Has been cancelled

Reviewed-on: #25
This commit was merged in pull request #25.
This commit is contained in:
2026-05-20 21:01:07 +01:00
+47 -9
View File
@@ -37,17 +37,35 @@ class PollingRadarrRetriever extends ArrRetriever {
* @returns {Promise<Object>} Queue object with records array * @returns {Promise<Object>} Queue object with records array
*/ */
async getQueue() { async getQueue() {
const instanceName = this.name;
let page = 1;
let allRecords = [];
let responseData = null;
do {
try { try {
// Fetch with large page size to get all items (Radarr has pagination)
const response = await axios.get(`${this.url}/api/v3/queue`, { const response = await axios.get(`${this.url}/api/v3/queue`, {
headers: { 'X-Api-Key': this.apiKey }, headers: { 'X-Api-Key': this.apiKey },
params: { includeMovie: true, pageSize: 1000 } params: { includeMovie: true, page, pageSize: 1000 }
}); });
return response.data; responseData = response.data;
} catch (error) { } catch (error) {
logToFile(`[PollingRadarrRetriever] ${this.id} queue error: ${error.message}`); console.error(`Radarr queue fetch failed for instance ${instanceName}:`, error.response?.data || error.message);
return { records: [] }; throw error;
} }
const records = responseData.records || (Array.isArray(responseData) ? responseData : []);
allRecords = allRecords.concat(records);
page++;
} while (
(responseData.records || (Array.isArray(responseData) ? responseData : [])).length === 1000 &&
page <= 50
);
return {
...responseData,
records: allRecords
};
} }
/** /**
@@ -69,8 +87,14 @@ class PollingRadarrRetriever extends ArrRetriever {
startDate startDate
} = options; } = options;
try { const instanceName = this.name;
let page = 1;
let allRecords = [];
let responseData = null;
do {
const params = { const params = {
page,
pageSize, pageSize,
includeMovie includeMovie
}; };
@@ -79,15 +103,29 @@ class PollingRadarrRetriever extends ArrRetriever {
if (sortDir) params.sortDir = sortDir; if (sortDir) params.sortDir = sortDir;
if (startDate) params.startDate = startDate; if (startDate) params.startDate = startDate;
try {
const response = await axios.get(`${this.url}/api/v3/history`, { const response = await axios.get(`${this.url}/api/v3/history`, {
headers: { 'X-Api-Key': this.apiKey }, headers: { 'X-Api-Key': this.apiKey },
params params
}); });
return response.data; responseData = response.data;
} catch (error) { } catch (error) {
logToFile(`[PollingRadarrRetriever] ${this.id} history error: ${error.message}`); console.error(`Radarr history fetch failed for instance ${instanceName}:`, error.response?.data || error.message);
return { records: [] }; throw error;
} }
const records = responseData.records || (Array.isArray(responseData) ? responseData : []);
allRecords = allRecords.concat(records);
page++;
} while (
(responseData.records || (Array.isArray(responseData) ? responseData : [])).length === pageSize &&
page <= 50
);
return {
...responseData,
records: allRecords
};
} }
} }