Add write-through cache for per-item track/episode data
lidarr_cleanup.sh and sonarr_cleanup.sh already walk every artist/series individually (trackFile/episodefile) for their own cleanup decisions -- that walk now also writes the raw per-item data through to a short-lived tmpfs cache (arr_item_cache_write, 4h freshness, no persistent backup since every consumer already has its own live fallback). lidarr_missing_art.sh runs later in the same nightly window and now reads that cache first, skipping its own redundant per-artist walk entirely on a hit. Sonarr side is write-through only for now -- no second consumer exists yet, but the data's there for whenever one does. Future consumers: arr_get_cached_items() first, live per-item fetch as fallback, same pattern as these two.
This commit is contained in:
@@ -310,9 +310,17 @@ TRACKED_FILE="$TMP_DIR/tracked_paths.txt"
|
||||
# Fetches every series' episode-file paths fresh into TRACKED_FILE/TRACKED_MAP/TRACKED_COUNT.
|
||||
# Pulled into a function so the rescan-aware retry below can re-fetch after waiting without
|
||||
# duplicating this whole loop inline.
|
||||
#
|
||||
# Write-through — also caches the raw per-episode data via arr_item_cache_write() (2026-07-17)
|
||||
# for any future script that needs Sonarr's per-episode file data — none exist yet (unlike
|
||||
# Lidarr, where lidarr_missing_art.sh already reads this), but the walk is happening regardless
|
||||
# for our own cleanup decisions, so the cache write is free by comparison. Future consumers:
|
||||
# call arr_get_cached_items("sonarr") first, fall back to your own live walk on a miss.
|
||||
_fetch_tracked_files() {
|
||||
> "$TRACKED_FILE"
|
||||
local _series_index=0
|
||||
local all_episodes_tmp
|
||||
all_episodes_tmp=$(mktemp)
|
||||
while IFS= read -r series_id; do
|
||||
[[ -z "$series_id" ]] && continue
|
||||
(( _series_index++ ))
|
||||
@@ -320,6 +328,7 @@ _fetch_tracked_files() {
|
||||
log "Fetching files: $_series_index/$SERIES_COUNT series..."
|
||||
SERIES_FILES=$(arr_api "$SONARR_URL" "$SONARR_API_KEY" "v3" "episodefile?seriesId=${series_id}" "Sonarr" 2>/dev/null)
|
||||
if [[ -n "$SERIES_FILES" ]]; then
|
||||
echo "$SERIES_FILES" >> "$all_episodes_tmp"
|
||||
while IFS= read -r api_path; do
|
||||
[[ -z "$api_path" ]] && continue
|
||||
translate_path "$api_path" >> "$TRACKED_FILE"
|
||||
@@ -327,6 +336,9 @@ _fetch_tracked_files() {
|
||||
fi
|
||||
done <<< "$SERIES_IDS"
|
||||
|
||||
arr_item_cache_write "sonarr" "$(jq -s 'add // []' "$all_episodes_tmp" 2>/dev/null)"
|
||||
rm -f "$all_episodes_tmp"
|
||||
|
||||
sort -u "$TRACKED_FILE" -o "$TRACKED_FILE"
|
||||
|
||||
# Build in-memory lookup map — O(1) per lookup vs O(n) grep per file
|
||||
|
||||
Reference in New Issue
Block a user