Replace external basename with parameter expansion in matches_pattern_list

This turned out to be the actual dominant cost left in the cleanup
scripts' classification loop, hidden behind the stat/dirname forks fixed
earlier today -- called once per non-tracked file (most files in a
media library, since every protected sidecar counts). Measured: 47.3s
vs 1.65s for 10,000 calls (~28.6x), identical results confirmed via
spot check before switching. Only used by lidarr_cleanup.sh/
sonarr_cleanup.sh/radarr_cleanup.sh.
This commit is contained in:
Gmer4Lfe
2026-07-17 02:02:22 -04:00
parent d2e071dece
commit 587fae1539
+8 -2
View File
@@ -2124,10 +2124,16 @@ has_extension() {
# True if filepath's basename matches one of the given glob patterns.
# Usage: matches_pattern_list "$filepath" "${LIDARR_PROTECTED_PATTERNS[@]}"
#
# Parameter expansion instead of external basename (2026-07-17) — called once per
# non-tracked file in lidarr_cleanup.sh/sonarr_cleanup.sh/radarr_cleanup.sh's classification
# loop, which is most files in a media library (every protected sidecar: nfo/jpg/srt/etc).
# Measured: this was the actual dominant cost left in those scripts even after fixing the
# per-file stat fork and dirname elsewhere — 47.3s vs 1.65s for 10,000 calls (~28.6x),
# confirmed identical results across a spot check first.
matches_pattern_list() {
local filepath="$1"; shift
local filename
filename=$(basename "$filepath")
local filename="${filepath##*/}"
local pattern
for pattern in "$@"; do
# shellcheck disable=SC2254