Move arr tracked-data cache to tmpfs, keep disk copy as persistent backup
Reads/writes now hit tmpfs (ARR_CACHE_DIR) instead of the array disk -- a full rebuild for all three arrs measures ~12s live, so there's no real cost to losing it on reboot. The existing on-disk file becomes a backup that arr_cache_write() keeps in sync on every write, and arr_cache_age_seconds() transparently restores it into tmpfs the moment it notices tmpfs is missing -- so a cache that was fresh before reboot reads as fresh after too, closing the cold-start gap without needing a dedicated restore step anywhere else.
This commit is contained in:
@@ -2294,7 +2294,17 @@ declare -gA ARR_API_VERSION=(
|
|||||||
[radarr]="v3"
|
[radarr]="v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
arr_cache_file() { echo "${DATA_DIR}/${1}_tracked_cache.json"; }
|
# tmpfs — primary read/write location. Cleared every reboot; that's fine, a full rebuild for
|
||||||
|
# all three arrs measures ~12s live, and arr_cache_age_seconds() transparently restores from
|
||||||
|
# the persistent backup below the moment it notices this is missing.
|
||||||
|
arr_cache_file() { echo "${ARR_CACHE_DIR}/${1}_tracked_cache.json"; }
|
||||||
|
|
||||||
|
# Persistent backup — survives reboot. Kept in sync by arr_cache_write() dual-writing here on
|
||||||
|
# every write, so it's never more than one write-cycle stale (2026-07-17). Exists purely so a
|
||||||
|
# reboot doesn't leave the tmpfs cache genuinely empty until the next live fetch completes —
|
||||||
|
# not a source of truth in its own right, just what tmpfs gets restored from when missing.
|
||||||
|
arr_cache_backup_file() { echo "${DATA_DIR}/${1}_tracked_cache.json"; }
|
||||||
|
|
||||||
arr_rescan_duration_db() { echo "${DATA_DIR}/${1}_rescan_duration.db"; }
|
arr_rescan_duration_db() { echo "${DATA_DIR}/${1}_rescan_duration.db"; }
|
||||||
|
|
||||||
# Writes the current library-list JSON + computed total tracked count to arr_type's cache.
|
# Writes the current library-list JSON + computed total tracked count to arr_type's cache.
|
||||||
@@ -2332,14 +2342,16 @@ arr_cache_write() {
|
|||||||
total=$(echo "$items_json" | jq "$expr" 2>/dev/null)
|
total=$(echo "$items_json" | jq "$expr" 2>/dev/null)
|
||||||
[[ -z "$total" || "$total" == "null" ]] && return 1
|
[[ -z "$total" || "$total" == "null" ]] && return 1
|
||||||
|
|
||||||
local cache_file items_tmp
|
local cache_file backup_file items_tmp
|
||||||
cache_file=$(arr_cache_file "$arr_type")
|
cache_file=$(arr_cache_file "$arr_type")
|
||||||
|
backup_file=$(arr_cache_backup_file "$arr_type")
|
||||||
items_tmp=$(mktemp)
|
items_tmp=$(mktemp)
|
||||||
echo "$items_json" > "$items_tmp"
|
echo "$items_json" > "$items_tmp"
|
||||||
mkdir -p "$(dirname "$cache_file")" 2>/dev/null
|
mkdir -p "$(dirname "$cache_file")" "$(dirname "$backup_file")" 2>/dev/null
|
||||||
jq -c -n --slurpfile items "$items_tmp" --argjson total "$total" --argjson ts "$(date +%s)" \
|
jq -c -n --slurpfile items "$items_tmp" --argjson total "$total" --argjson ts "$(date +%s)" \
|
||||||
'{ts:$ts, totalTracked:$total, items:$items[0]}' > "${cache_file}.tmp" 2>/dev/null \
|
'{ts:$ts, totalTracked:$total, items:$items[0]}' > "${cache_file}.tmp" 2>/dev/null \
|
||||||
&& mv "${cache_file}.tmp" "$cache_file"
|
&& mv "${cache_file}.tmp" "$cache_file" \
|
||||||
|
&& cp "$cache_file" "$backup_file" 2>/dev/null
|
||||||
rm -f "$items_tmp"
|
rm -f "$items_tmp"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2353,12 +2365,22 @@ arr_cache_read_raw() {
|
|||||||
jq -c '.items // empty' "$cache_file" 2>/dev/null
|
jq -c '.items // empty' "$cache_file" 2>/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
# Echoes arr_type's cache age in seconds, or a very large number if no cache exists (so age
|
# Echoes arr_type's cache age in seconds, or a very large number if no cache and no backup
|
||||||
# comparisons naturally treat "no cache" the same as "very stale cache").
|
# exist (so age comparisons naturally treat that as "very stale"). Transparently restores the
|
||||||
|
# tmpfs cache from its persistent backup first if tmpfs is missing (e.g. right after a reboot)
|
||||||
|
# — a cache that was fresh before reboot reads as fresh here too, not as if it never existed.
|
||||||
arr_cache_age_seconds() {
|
arr_cache_age_seconds() {
|
||||||
local arr_type="$1"
|
local arr_type="$1"
|
||||||
local cache_file
|
local cache_file
|
||||||
cache_file=$(arr_cache_file "$arr_type")
|
cache_file=$(arr_cache_file "$arr_type")
|
||||||
|
if [[ ! -f "$cache_file" ]]; then
|
||||||
|
local backup_file
|
||||||
|
backup_file=$(arr_cache_backup_file "$arr_type")
|
||||||
|
if [[ -f "$backup_file" ]]; then
|
||||||
|
mkdir -p "$(dirname "$cache_file")" 2>/dev/null
|
||||||
|
cp "$backup_file" "$cache_file" 2>/dev/null
|
||||||
|
fi
|
||||||
|
fi
|
||||||
[[ -f "$cache_file" ]] || { echo 999999999; return; }
|
[[ -f "$cache_file" ]] || { echo 999999999; return; }
|
||||||
local ts
|
local ts
|
||||||
ts=$(jq -r '.ts // 0' "$cache_file" 2>/dev/null)
|
ts=$(jq -r '.ts // 0' "$cache_file" 2>/dev/null)
|
||||||
|
|||||||
+2
-1
@@ -136,7 +136,8 @@
|
|||||||
LOG_DIR="/var/log/varaverk"
|
LOG_DIR="/var/log/varaverk"
|
||||||
VV_CACHE_DIR="/tmp/vv_cache"
|
VV_CACHE_DIR="/tmp/vv_cache"
|
||||||
CONF_RAM_CACHE_DIR="/tmp/.cache/vv/d" # tmpfs — cleared every reboot, repopulated by conf_sync.sh
|
CONF_RAM_CACHE_DIR="/tmp/.cache/vv/d" # tmpfs — cleared every reboot, repopulated by conf_sync.sh
|
||||||
export CONF_DIR LOG_DIR VV_CACHE_DIR CONF_RAM_CACHE_DIR
|
ARR_CACHE_DIR="/tmp/arr_cache" # tmpfs — cleared every reboot, restored from DATA_DIR backup by arr_cache_age_seconds()
|
||||||
|
export CONF_DIR LOG_DIR VV_CACHE_DIR CONF_RAM_CACHE_DIR ARR_CACHE_DIR
|
||||||
|
|
||||||
# ━━━ Cleanup ━━━
|
# ━━━ Cleanup ━━━
|
||||||
unset _conf _host_confs_loaded _adapter LOAD_CONFIG_DIR
|
unset _conf _host_confs_loaded _adapter LOAD_CONFIG_DIR
|
||||||
Reference in New Issue
Block a user