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:
@@ -2124,10 +2124,16 @@ has_extension() {
|
|||||||
|
|
||||||
# True if filepath's basename matches one of the given glob patterns.
|
# True if filepath's basename matches one of the given glob patterns.
|
||||||
# Usage: matches_pattern_list "$filepath" "${LIDARR_PROTECTED_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() {
|
matches_pattern_list() {
|
||||||
local filepath="$1"; shift
|
local filepath="$1"; shift
|
||||||
local filename
|
local filename="${filepath##*/}"
|
||||||
filename=$(basename "$filepath")
|
|
||||||
local pattern
|
local pattern
|
||||||
for pattern in "$@"; do
|
for pattern in "$@"; do
|
||||||
# shellcheck disable=SC2254
|
# shellcheck disable=SC2254
|
||||||
|
|||||||
Reference in New Issue
Block a user