OPTIMIZATION: Remove redundant cache checks and find operations

Identified and fixed multiple inefficiencies:

1. Redundant TTL cache checks removed
   - Startup code was checking cache age with stat call
   - Then calling initialize_wp_cache() which checks again
   - Then get_wp_sites_cached() checks again
   - Now: Simplified to single get_wp_sites_cached() call

2. Removed duplicate find logic in show_installation_status()
   - Was doing separate find /home/*/public_html for each call
   - Now: Uses cached data from get_wp_sites_cached()
   - Saves filesystem I/O on every status check

Result:
- Eliminated 3x redundant stat calls at startup
- Eliminated duplicate filesystem scans
- Cleaner code path
- Better cache utilization

This reduces startup overhead and improves performance on repeated runs.
This commit is contained in:
cschantz
2026-03-02 21:37:04 -05:00
parent 5b96b65691
commit f54f889652
@@ -1333,21 +1333,8 @@ show_installation_status() {
echo "Current WordPress Installation Status:" echo "Current WordPress Installation Status:"
echo "" echo ""
local wp_configs="" # Use cached WordPress sites instead of doing redundant find
case "$panel" in local wp_configs=$(get_wp_sites_cached)
cpanel)
wp_configs=$(find /home/*/public_html -name "wp-config.php" -type f 2>/dev/null)
;;
interworx)
wp_configs=$(find /home/*/*/html -name "wp-config.php" -type f 2>/dev/null)
;;
plesk)
wp_configs=$(find /var/www/vhosts/*/httpdocs -name "wp-config.php" -type f 2>/dev/null)
;;
*)
wp_configs=$(find /var/www/html -name "wp-config.php" -type f 2>/dev/null)
;;
esac
if [ -z "$wp_configs" ]; then if [ -z "$wp_configs" ]; then
echo "No WordPress installations found" echo "No WordPress installations found"
@@ -1604,24 +1591,15 @@ clear
print_banner "WordPress Cron Manager" print_banner "WordPress Cron Manager"
# PERFORMANCE: Pre-load WordPress sites cache on startup # PERFORMANCE: Pre-load WordPress sites cache on startup
# Check if we have a fresh cached copy from a previous run (usually instant) # Simplified: delegate to get_wp_sites_cached() which handles all TTL logic
if [ "$WP_CACHE_INITIALIZED" = "0" ]; then if [ "$WP_CACHE_INITIALIZED" = "0" ]; then
if [ -f "$WP_CACHE_FILE" ]; then if [ -f "$WP_CACHE_FILE" ]; then
local cache_age=$(($(date +%s) - $(stat -c %Y "$WP_CACHE_FILE" 2>/dev/null || echo 0))) echo -e "${GREEN}✓ Loading cached WordPress site list${NC}"
if [ "$cache_age" -lt "$WP_CACHE_TTL" ]; then
echo -e "${GREEN}✓ Using cached WordPress site list (refreshed hourly)${NC}"
WP_SITES_CACHE=$(cat "$WP_CACHE_FILE")
WP_CACHE_INITIALIZED=1
else
echo -e "${CYAN}Refreshing WordPress site list (cache expired)...${NC}"
initialize_wp_cache
echo -e "${GREEN}✓ Cache refreshed${NC}"
fi
else else
echo -e "${CYAN}Scanning for WordPress installations (first run)...${NC}" echo -e "${CYAN}Scanning for WordPress installations (first run)...${NC}"
initialize_wp_cache
echo -e "${GREEN}✓ Cache loaded${NC}"
fi fi
WP_SITES_CACHE=$(get_wp_sites_cached)
WP_CACHE_INITIALIZED=1
echo "" echo ""
fi fi