1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-05 09:08:49 +00:00

Spotlight cache cleaning moved to the optimize command

This commit is contained in:
Tw93
2025-12-10 10:02:49 +08:00
parent 4ff8c3afa3
commit 198591289f
5 changed files with 54 additions and 4 deletions

View File

@@ -127,6 +127,7 @@ EOF
items+=('recent_items|Recent Items|Clear recent apps/documents/servers lists|true')
items+=('log_cleanup|Diagnostics Cleanup|Purge old diagnostic & crash logs|true')
items+=('startup_cache|Startup Cache Rebuild|Rebuild kext caches & prelinked kernel|true')
items+=('spotlight_cache_cleanup|Spotlight Cache Cleanup|Clear CoreSpotlight user cache|false')
# Output items as JSON
local first=true

View File

@@ -216,8 +216,6 @@ clean_project_caches() {
}
# Clean Spotlight user caches
# Cleans CoreSpotlight index cache and Spotlight saved state
# System Spotlight index (/System/Volumes/Data/.Spotlight-V100) is never touched
clean_spotlight_caches() {
local cleaned_size=0
local cleaned_count=0

View File

@@ -80,8 +80,7 @@ clean_macos_system_caches() {
safe_clean ~/Library/Saved\ Application\ State/* "Saved application states"
safe_clean ~/Library/Caches/com.apple.spotlight "Spotlight cache"
# Clean Spotlight user caches (CoreSpotlight can grow very large)
clean_spotlight_caches
# MOVED: Spotlight cache cleanup moved to optimize command
safe_clean ~/Library/Caches/com.apple.photoanalysisd "Photo analysis cache"
safe_clean ~/Library/Caches/com.apple.akd "Apple ID cache"

View File

@@ -163,6 +163,7 @@ TouchID sudo check|check_touchid|config_check
Rosetta 2 check|check_rosetta|config_check
Git configuration check|check_git_config|config_check
Login items check|check_login_items|config_check
Spotlight cache cleanup|spotlight_cache|system_optimization
EOF
}

View File

@@ -410,6 +410,56 @@ opt_fix_broken_configs() {
fi
}
# Clean Spotlight user caches
opt_spotlight_cache_cleanup() {
# Check whitelist
if is_whitelisted "spotlight_cache"; then
echo -e "${GRAY}${ICON_SUCCESS}${NC} Spotlight cache cleanup (whitelisted)"
return 0
fi
echo -e "${BLUE}${ICON_ARROW}${NC} Cleaning Spotlight user caches..."
local cleaned_count=0
local total_size_kb=0
# CoreSpotlight user cache (can grow very large)
local spotlight_cache="$HOME/Library/Metadata/CoreSpotlight"
if [[ -d "$spotlight_cache" ]]; then
local size_kb=$(get_path_size_kb "$spotlight_cache")
if [[ "$size_kb" -gt 0 ]]; then
local size_human=$(bytes_to_human "$((size_kb * 1024))")
if safe_remove "$spotlight_cache" true; then
echo -e " ${GREEN}${ICON_SUCCESS}${NC} CoreSpotlight cache ${GREEN}($size_human)${NC}"
((cleaned_count++))
((total_size_kb += size_kb))
fi
fi
fi
# Spotlight saved application state
local spotlight_state="$HOME/Library/Saved Application State/com.apple.spotlight.Spotlight.savedState"
if [[ -d "$spotlight_state" ]]; then
local size_kb=$(get_path_size_kb "$spotlight_state")
if [[ "$size_kb" -gt 0 ]]; then
local size_human=$(bytes_to_human "$((size_kb * 1024))")
if safe_remove "$spotlight_state" true; then
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Spotlight state ${GREEN}($size_human)${NC}"
((cleaned_count++))
((total_size_kb += size_kb))
fi
fi
fi
if [[ $cleaned_count -gt 0 ]]; then
local total_human=$(bytes_to_human "$((total_size_kb * 1024))")
echo -e "${GREEN}${ICON_SUCCESS}${NC} Cleaned $cleaned_count items ${GREEN}($total_human)${NC}"
echo -e "${YELLOW}${ICON_WARNING}${NC} System settings may require logout/restart to display correctly"
else
echo -e "${GREEN}${ICON_SUCCESS}${NC} No Spotlight caches to clean"
fi
}
# Execute optimization by action name
execute_optimization() {
local action="$1"
@@ -430,6 +480,7 @@ execute_optimization() {
local_snapshots) opt_local_snapshots ;;
developer_cleanup) opt_developer_cleanup ;;
fix_broken_configs) opt_fix_broken_configs ;;
spotlight_cache_cleanup) opt_spotlight_cache_cleanup ;;
*)
echo -e "${RED}${ICON_ERROR}${NC} Unknown action: $action"
return 1