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

refactor: improve database optimization spinner handling and network optimization success tracking.

This commit is contained in:
Tw93
2025-12-30 18:16:22 +08:00
parent bb49ec3170
commit a7b071e8f6

View File

@@ -225,7 +225,6 @@ opt_sqlite_vacuum() {
if [[ "${MOLE_DRY_RUN:-0}" != "1" && -t 1 ]]; then if [[ "${MOLE_DRY_RUN:-0}" != "1" && -t 1 ]]; then
MOLE_SPINNER_PREFIX=" " start_inline_spinner "Optimizing databases..." MOLE_SPINNER_PREFIX=" " start_inline_spinner "Optimizing databases..."
spinner_started="true" spinner_started="true"
trap '[[ "${spinner_started:-false}" == "true" ]] && stop_inline_spinner' RETURN
fi fi
local -a db_paths=( local -a db_paths=(
@@ -312,6 +311,10 @@ opt_sqlite_vacuum() {
done < <(compgen -G "$pattern" || true) done < <(compgen -G "$pattern" || true)
done done
if [[ "$spinner_started" == "true" ]]; then
stop_inline_spinner
fi
if [[ $vacuumed -gt 0 ]]; then if [[ $vacuumed -gt 0 ]]; then
opt_msg "Optimized $vacuumed databases for Mail, Safari, Messages" opt_msg "Optimized $vacuumed databases for Mail, Safari, Messages"
elif [[ $timed_out -eq 0 && $failed -eq 0 ]]; then elif [[ $timed_out -eq 0 && $failed -eq 0 ]]; then
@@ -428,7 +431,8 @@ opt_memory_pressure_relief() {
# Network stack optimization # Network stack optimization
# Flushes routing table and ARP cache to resolve network issues # Flushes routing table and ARP cache to resolve network issues
opt_network_stack_optimize() { opt_network_stack_optimize() {
local success=0 local route_flushed="false"
local arp_flushed="false"
if [[ "${MOLE_DRY_RUN:-0}" != "1" ]]; then if [[ "${MOLE_DRY_RUN:-0}" != "1" ]]; then
local route_ok=true local route_ok=true
@@ -448,21 +452,27 @@ opt_network_stack_optimize() {
# Flush routing table # Flush routing table
if sudo route -n flush > /dev/null 2>&1; then if sudo route -n flush > /dev/null 2>&1; then
((success++)) route_flushed="true"
fi fi
# Clear ARP cache # Clear ARP cache
if sudo arp -a -d > /dev/null 2>&1; then if sudo arp -a -d > /dev/null 2>&1; then
((success++)) arp_flushed="true"
fi fi
else else
success=2 route_flushed="true"
arp_flushed="true"
fi fi
if [[ $success -gt 0 ]]; then if [[ "$route_flushed" == "true" ]]; then
opt_msg "Network routing table refreshed" opt_msg "Network routing table refreshed"
fi
if [[ "$arp_flushed" == "true" ]]; then
opt_msg "ARP cache cleared" opt_msg "ARP cache cleared"
else else
if [[ "$route_flushed" == "true" ]]; then
return 0
fi
echo -e " ${YELLOW}!${NC} Failed to optimize network stack" echo -e " ${YELLOW}!${NC} Failed to optimize network stack"
fi fi
} }