From 587fae1539f015ee27604aff296b313fa1a0908e Mon Sep 17 00:00:00 2001 From: Gmer4Lfe Date: Fri, 17 Jul 2026 02:02:22 -0400 Subject: [PATCH] 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. --- common.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/common.sh b/common.sh index 40de7c1..4682e8e 100755 --- a/common.sh +++ b/common.sh @@ -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