Paginate get_queue_data() so the recovery script actually sees the whole queue
page=1&pageSize=200 silently truncated anything past record 200. Sonarr's queue currently runs 1700+ during a large search campaign, which pushed every importBlocked/warning item past page 1 — the script logged 'clean' every run while 52 stuck imports sat completely unseen despite yesterday's importBlocked fix matching them correctly once actually queried.
This commit is contained in:
@@ -212,14 +212,41 @@ item_is_old_enough() {
|
|||||||
[[ "$age_seconds" -ge "$AGE_THRESHOLD_SECONDS" ]]
|
[[ "$age_seconds" -ge "$AGE_THRESHOLD_SECONDS" ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
# Query the arr queue API and return all records
|
# Query the arr queue API and return all records, paginated.
|
||||||
|
# A single page=1&pageSize=200 request silently misses everything past record 200 —
|
||||||
|
# on a busy Sonarr instance the queue can run into the thousands (e.g. a large
|
||||||
|
# missing-episode search campaign), which pushed every importBlocked/warning item
|
||||||
|
# past page 1 and made this whole script blind to them despite matching correctly.
|
||||||
# Args: url, api_key, api_version
|
# Args: url, api_key, api_version
|
||||||
get_queue_data() {
|
get_queue_data() {
|
||||||
local url="$1" api_key="$2" api_version="$3"
|
local url="$1" api_key="$2" api_version="$3"
|
||||||
curl -sf --max-time 15 \
|
local page=1 page_size=250 max_pages=50
|
||||||
|
local page_data page_count
|
||||||
|
# Accumulate pages as files rather than growing a shell variable — on a large
|
||||||
|
# queue (thousands of records) passing the combined JSON through --argjson
|
||||||
|
# blows past ARG_MAX ("Argument list too long"). jq -s reads files instead.
|
||||||
|
local tmp_dir
|
||||||
|
tmp_dir=$(mktemp -d)
|
||||||
|
trap 'rm -rf "$tmp_dir"' RETURN
|
||||||
|
|
||||||
|
while [[ "$page" -le "$max_pages" ]]; do
|
||||||
|
page_data=$(curl -sf --max-time 15 \
|
||||||
-H "X-Api-Key: $api_key" \
|
-H "X-Api-Key: $api_key" \
|
||||||
"${url}/api/${api_version}/queue?page=1&pageSize=200&includeUnknownSeriesItems=true&includeUnknownArtistItems=true" \
|
"${url}/api/${api_version}/queue?page=${page}&pageSize=${page_size}&includeUnknownSeriesItems=true&includeUnknownArtistItems=true" \
|
||||||
2>/dev/null
|
2>/dev/null)
|
||||||
|
[[ -z "$page_data" ]] && break
|
||||||
|
|
||||||
|
page_count=$(echo "$page_data" | jq '.records // [] | length' 2>/dev/null)
|
||||||
|
[[ -z "$page_count" || "$page_count" -eq 0 ]] && break
|
||||||
|
|
||||||
|
echo "$page_data" | jq -c '.records // []' > "$tmp_dir/page_${page}.json"
|
||||||
|
|
||||||
|
[[ "$page_count" -lt "$page_size" ]] && break
|
||||||
|
(( page++ ))
|
||||||
|
done
|
||||||
|
|
||||||
|
jq -c -s '{totalRecords: ([.[][]] | length), records: [.[][]]}' "$tmp_dir"/page_*.json 2>/dev/null \
|
||||||
|
|| echo '{"totalRecords":0,"records":[]}'
|
||||||
}
|
}
|
||||||
|
|
||||||
# Blocklist and remove a queue item
|
# Blocklist and remove a queue item
|
||||||
|
|||||||
Reference in New Issue
Block a user