Make all arr library-list fetches cache-first with live fallback
Every script that fetches the full Lidarr/Sonarr/Radarr tracked-library list now goes through arr_get_tracked_data() instead of hitting the API directly -- cache-first when fresh, live fetch as fallback when stale, waits out an active rescan before either. Per-item file data (trackFile/ episodefile/moviefile) stays live-only everywhere, since that's the actual disk-truth these scripts' decisions depend on and was never part of what's cached. Also adds arr_cache_prefill.sh to CRITICAL_MAINTENANCE_SCRIPTS (30min tier) with a short 1min wait ceiling, so the cache stays consistently fresh instead of only refreshing whenever some other script happens to write through. A full cache refresh for all three arrs measured at ~12s total live -- nothing like the multi-hour cost of an actual rescan.
This commit is contained in:
@@ -279,15 +279,17 @@ check_arr_version "$SONARR_URL" "$SONARR_API_KEY" "v3" "$SONARR_VERSION_MAJOR" "
|
||||
|
||||
info "Querying Sonarr API..."
|
||||
|
||||
# Fetch all series
|
||||
SERIES_RESPONSE=$(arr_api "$SONARR_URL" "$SONARR_API_KEY" "v3" "series" "Sonarr") || {
|
||||
# Cache-first — arr_get_tracked_data() serves the shared cache when it's fresh (now kept
|
||||
# current every 30min by arr_cache_prefill.sh in CRITICAL_MAINTENANCE_SCRIPTS), falls back to
|
||||
# a live fetch when it's stale, and waits out an active rescan before either. Only the series
|
||||
# list itself is cached — the per-series episodeFile data below is never cached and always
|
||||
# live, since that's the actual disk-truth this script's cleanup decisions depend on.
|
||||
SERIES_RESPONSE=$(arr_get_tracked_data "sonarr" "$SONARR_URL" "$SONARR_API_KEY" "v3") || {
|
||||
error "Failed to fetch series from Sonarr"
|
||||
notify "Sonarr cleanup failed on $(hostname) — could not fetch series" \
|
||||
"Sonarr Cleanup" "warning"
|
||||
exit 1
|
||||
}
|
||||
# Write-through — free cache refresh from a fetch this script already needed.
|
||||
arr_cache_write "sonarr" "$SERIES_RESPONSE"
|
||||
|
||||
SERIES_IDS=$(echo "$SERIES_RESPONSE" | jq -r '.[].id' 2>/dev/null)
|
||||
SERIES_COUNT=$(echo "$SERIES_IDS" | grep -c "." 2>/dev/null || echo 0)
|
||||
|
||||
Reference in New Issue
Block a user