mirror of
https://github.com/tw93/Mole.git
synced 2026-03-22 21:20:09 +00:00
perf(purge/uninstall): eliminate per-item subprocess forks in scan phase
purge:
- is_safe_project_artifact: replace echo|tr|wc depth calc with pure bash
string arithmetic (2 forks → 0 per item)
- process_scan_results: replace dirname subprocess with ${item%/*}
- is_recently_modified: accept pre-computed epoch to avoid redundant
get_epoch_seconds call (N date forks → 1 before loop)
- fd pattern construction: replace 45 per-target sed forks with single
printf|sed pass (45 forks → 2)
- pre-compute _cached_project_paths alongside existing name/basename
cache so display loop avoids get_project_path subshell per item
uninstall/app-selector:
- default size display: N/A → -- for apps without cached size data
(cleaner UX on first scan; real sizes populate from background refresh)
- Pass 1 scan: replace basename/dirname subshells with parameter expansion
This commit is contained in:
@@ -469,12 +469,11 @@ scan_applications() {
|
||||
while IFS= read -r -d '' app_path; do
|
||||
if [[ ! -e "$app_path" ]]; then continue; fi
|
||||
|
||||
local app_name
|
||||
app_name=$(basename "$app_path" .app)
|
||||
local app_name="${app_path##*/}"
|
||||
app_name="${app_name%.app}"
|
||||
|
||||
# Skip nested apps inside another .app bundle.
|
||||
local parent_dir
|
||||
parent_dir=$(dirname "$app_path")
|
||||
local parent_dir="${app_path%/*}"
|
||||
if [[ "$parent_dir" == *".app" || "$parent_dir" == *".app/"* ]]; then
|
||||
continue
|
||||
fi
|
||||
@@ -485,9 +484,8 @@ scan_applications() {
|
||||
if [[ -n "$link_target" ]]; then
|
||||
local resolved_target="$link_target"
|
||||
if [[ "$link_target" != /* ]]; then
|
||||
local link_dir
|
||||
link_dir=$(dirname "$app_path")
|
||||
resolved_target=$(cd "$link_dir" 2> /dev/null && cd "$(dirname "$link_target")" 2> /dev/null && pwd)/$(basename "$link_target") 2> /dev/null || echo ""
|
||||
local link_dir="${app_path%/*}"
|
||||
resolved_target=$(cd "$link_dir" 2> /dev/null && cd "${link_target%/*}" 2> /dev/null && pwd)/"${link_target##*/}" 2> /dev/null || echo ""
|
||||
fi
|
||||
case "$resolved_target" in
|
||||
/System/* | /usr/bin/* | /usr/lib/* | /bin/* | /sbin/* | /private/etc/*)
|
||||
@@ -661,7 +659,7 @@ scan_applications() {
|
||||
fi
|
||||
|
||||
local final_size_kb=0
|
||||
local final_size="N/A"
|
||||
local final_size="--"
|
||||
if [[ "$cached_size_kb" =~ ^[0-9]+$ && $cached_size_kb -gt 0 ]]; then
|
||||
final_size_kb="$cached_size_kb"
|
||||
final_size=$(bytes_to_human "$((cached_size_kb * 1024))")
|
||||
|
||||
Reference in New Issue
Block a user