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:
@@ -180,7 +180,10 @@ fi
|
||||
echo ""
|
||||
echo "━━━ $ICON_SYNC Lidarr Library ━━━"
|
||||
|
||||
LIDARR_ARTISTS_JSON=$(_lidarr_get "artist") || { error "Could not fetch Lidarr artists"; exit 1; }
|
||||
# Cache-first — arr_get_tracked_data() serves the shared cache when it's fresh (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.
|
||||
LIDARR_ARTISTS_JSON=$(arr_get_tracked_data "lidarr" "$LIDARR_URL" "$LIDARR_API_KEY" "v1") || { error "Could not fetch Lidarr artists"; exit 1; }
|
||||
LIDARR_NAMES=$(echo "$LIDARR_ARTISTS_JSON" | jq -r '.[].artistName' 2>/dev/null)
|
||||
LIDARR_COUNT=$(echo "$LIDARR_NAMES" | grep -c . 2>/dev/null || echo 0)
|
||||
log "$LIDARR_COUNT artists already in Lidarr"
|
||||
|
||||
@@ -195,7 +195,10 @@ fi
|
||||
echo ""
|
||||
echo "━━━ $ICON_SYNC Radarr Library ━━━"
|
||||
|
||||
RADARR_MOVIES_JSON=$(_radarr_get "movie") || { error "Could not fetch Radarr movies"; exit 1; }
|
||||
# Cache-first — arr_get_tracked_data() serves the shared cache when it's fresh (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.
|
||||
RADARR_MOVIES_JSON=$(arr_get_tracked_data "radarr" "$RADARR_URL" "$RADARR_API_KEY" "v3") || { error "Could not fetch Radarr movies"; exit 1; }
|
||||
|
||||
declare -A RADARR_TMDB # tmdb_id → 1
|
||||
declare -A RADARR_TITLES # lower(title) → 1
|
||||
|
||||
@@ -189,7 +189,10 @@ fi
|
||||
echo ""
|
||||
echo "━━━ $ICON_SYNC Sonarr Library ━━━"
|
||||
|
||||
SONARR_SERIES_JSON=$(_sonarr_get "series") || { error "Could not fetch Sonarr series"; exit 1; }
|
||||
# Cache-first — arr_get_tracked_data() serves the shared cache when it's fresh (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.
|
||||
SONARR_SERIES_JSON=$(arr_get_tracked_data "sonarr" "$SONARR_URL" "$SONARR_API_KEY" "v3") || { error "Could not fetch Sonarr series"; exit 1; }
|
||||
|
||||
declare -A SONARR_TVDB # tvdb_id → 1
|
||||
declare -A SONARR_TITLES # lower(title) → 1
|
||||
|
||||
Reference in New Issue
Block a user