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:
@@ -329,12 +329,20 @@ TRACKED_FILE="$TMP_DIR/tracked_paths.txt"
|
||||
# Fetches every artist's track-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-track data via arr_item_cache_write() (2026-07-17)
|
||||
# so scripts running later in the same maintenance window (lidarr_missing_art.sh) can read it
|
||||
# instead of repeating this same per-artist walk. This walk is happening regardless for our
|
||||
# own cleanup decisions; the cache write is free by comparison. See common.sh for the pattern.
|
||||
_fetch_tracked_files() {
|
||||
> "$TRACKED_FILE"
|
||||
local all_tracks_tmp
|
||||
all_tracks_tmp=$(mktemp)
|
||||
while IFS= read -r artist_id; do
|
||||
[[ -z "$artist_id" ]] && continue
|
||||
ARTIST_TRACKS=$(arr_api "$LIDARR_URL" "$LIDARR_API_KEY" "v1" "trackFile?artistId=${artist_id}" "Lidarr" 2>/dev/null)
|
||||
if [[ -n "$ARTIST_TRACKS" ]]; then
|
||||
echo "$ARTIST_TRACKS" >> "$all_tracks_tmp"
|
||||
while IFS= read -r api_path; do
|
||||
[[ -z "$api_path" ]] && continue
|
||||
translate_path "$api_path" >> "$TRACKED_FILE"
|
||||
@@ -342,6 +350,9 @@ _fetch_tracked_files() {
|
||||
fi
|
||||
done <<< "$ARTIST_IDS"
|
||||
|
||||
arr_item_cache_write "lidarr" "$(jq -s 'add // []' "$all_tracks_tmp" 2>/dev/null)"
|
||||
rm -f "$all_tracks_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