mirror of
https://github.com/tw93/Mole.git
synced 2026-03-22 20:50:06 +00:00
perf(clean): speed up scan phase across all modules
- Parallelize project cache indicator checks and root scans in caches.sh
(sequential find per $HOME/* dir → throttled background jobs)
- Pre-compute project name cache before purge display loop, eliminating
O(N²) filesystem traversals in get_artifact_display_name
- Replace basename/dirname subshells with parameter expansion in
get_project_name/get_project_path hot loops; depth counter via
bash string arithmetic instead of echo|tr|wc|tr pipeline
- Eliminate mktemp/awk/rm per call in app_support_item_size_bytes,
use command substitution to capture du output directly
- Defer tr lowercase in clean_application_support_logs to only when
first 3 protection checks fail; replace basename with ${var##*/}
- Optimize trash item counting: find -print0|tr -dc '\0'|wc -c
avoids per-file fork from -exec printf
- Add -maxdepth 5 to /private/var/folders find (X dir is always at
depth 3, code_sign_clone at depth 5 max; verified on real machine)
This commit is contained in:
@@ -129,12 +129,18 @@ discover_project_cache_roots() {
|
||||
[[ -d "$root" ]] && roots+=("$root")
|
||||
done < <(mole_purge_read_paths_config "$HOME/.config/mole/purge_paths")
|
||||
|
||||
local _indicator_tmp
|
||||
_indicator_tmp=$(create_temp_file)
|
||||
local -a _indicator_pids=()
|
||||
local _max_jobs
|
||||
_max_jobs=$(get_optimal_parallel_jobs scan)
|
||||
|
||||
local dir
|
||||
local base
|
||||
for dir in "$HOME"/*/; do
|
||||
[[ -d "$dir" ]] || continue
|
||||
dir="${dir%/}"
|
||||
base=$(basename "$dir")
|
||||
base="${dir##*/}"
|
||||
|
||||
case "$base" in
|
||||
.* | Library | Applications | Movies | Music | Pictures | Public)
|
||||
@@ -142,10 +148,23 @@ discover_project_cache_roots() {
|
||||
;;
|
||||
esac
|
||||
|
||||
if project_cache_has_indicators "$dir" 5; then
|
||||
roots+=("$dir")
|
||||
(project_cache_has_indicators "$dir" 5 && echo "$dir" >> "$_indicator_tmp") &
|
||||
_indicator_pids+=($!)
|
||||
|
||||
if [[ ${#_indicator_pids[@]} -ge $_max_jobs ]]; then
|
||||
wait "${_indicator_pids[0]}" 2> /dev/null || true
|
||||
_indicator_pids=("${_indicator_pids[@]:1}")
|
||||
fi
|
||||
done
|
||||
for _pid in "${_indicator_pids[@]}"; do
|
||||
wait "$_pid" 2> /dev/null || true
|
||||
done
|
||||
|
||||
local _found_dir
|
||||
while IFS= read -r _found_dir; do
|
||||
[[ -n "$_found_dir" ]] && roots+=("$_found_dir")
|
||||
done < "$_indicator_tmp"
|
||||
rm -f "$_indicator_tmp"
|
||||
|
||||
[[ ${#roots[@]} -eq 0 ]] && return 0
|
||||
|
||||
@@ -211,8 +230,13 @@ clean_project_caches() {
|
||||
start_inline_spinner "Searching project caches..."
|
||||
fi
|
||||
|
||||
local -a _scan_pids=()
|
||||
for root in "${scan_roots[@]}"; do
|
||||
scan_project_cache_root "$root" "$matches_tmp_file"
|
||||
scan_project_cache_root "$root" "$matches_tmp_file" &
|
||||
_scan_pids+=($!)
|
||||
done
|
||||
for _pid in "${_scan_pids[@]}"; do
|
||||
wait "$_pid" 2> /dev/null || true
|
||||
done
|
||||
|
||||
if [[ -t 1 ]]; then
|
||||
|
||||
Reference in New Issue
Block a user