1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-04 15:04:42 +00:00

fix: improve performance of cache cleanup using find -delete

This commit is contained in:
tw93
2026-01-31 20:19:38 +08:00
parent 8ac71a3937
commit 7d62fa5e65

View File

@@ -457,7 +457,9 @@ process_container_cache() {
found_any=true found_any=true
((cleaned_count++)) ((cleaned_count++))
if [[ "$DRY_RUN" != "true" ]]; then if [[ "$DRY_RUN" != "true" ]]; then
# Clean contents safely with local nullglob. # For directories with many files, use find -delete for performance
if ! find "$cache_dir" -mindepth 1 -delete 2> /dev/null; then
# Fallback: try item-by-item if find fails
local _ng_state local _ng_state
_ng_state=$(shopt -p nullglob || true) _ng_state=$(shopt -p nullglob || true)
shopt -s nullglob shopt -s nullglob
@@ -468,6 +470,7 @@ process_container_cache() {
eval "$_ng_state" eval "$_ng_state"
fi fi
fi fi
fi
} }
# Browser caches (Safari/Chrome/Edge/Firefox). # Browser caches (Safari/Chrome/Edge/Firefox).
clean_browsers() { clean_browsers() {
@@ -604,6 +607,10 @@ clean_application_support_logs() {
((cleaned_count++)) ((cleaned_count++))
found_any=true found_any=true
if [[ "$DRY_RUN" != "true" ]]; then if [[ "$DRY_RUN" != "true" ]]; then
# For directories with many files, use find -delete for performance
# This avoids shell expansion and individual safe_remove calls
if ! find "$candidate" -mindepth 1 -delete 2> /dev/null; then
# Fallback: try item-by-item if find fails
for item in "$candidate"/*; do for item in "$candidate"/*; do
[[ -e "$item" ]] || continue [[ -e "$item" ]] || continue
safe_remove "$item" true > /dev/null 2>&1 || true safe_remove "$item" true > /dev/null 2>&1 || true
@@ -611,6 +618,7 @@ clean_application_support_logs() {
fi fi
fi fi
fi fi
fi
done done
done done
eval "$_ng_state" eval "$_ng_state"