From f54f889652f28d55b523d83b45c16e3c2ac1d194 Mon Sep 17 00:00:00 2001 From: cschantz Date: Mon, 2 Mar 2026 21:37:04 -0500 Subject: [PATCH] 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. --- .../wordpress/wordpress-cron-manager.sh | 34 ++++--------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/modules/website/wordpress/wordpress-cron-manager.sh b/modules/website/wordpress/wordpress-cron-manager.sh index 31cc184..ea1ed0c 100755 --- a/modules/website/wordpress/wordpress-cron-manager.sh +++ b/modules/website/wordpress/wordpress-cron-manager.sh @@ -1333,21 +1333,8 @@ show_installation_status() { echo "Current WordPress Installation Status:" echo "" - local wp_configs="" - case "$panel" in - 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 + # Use cached WordPress sites instead of doing redundant find + local wp_configs=$(get_wp_sites_cached) if [ -z "$wp_configs" ]; then echo "No WordPress installations found" @@ -1604,24 +1591,15 @@ clear print_banner "WordPress Cron Manager" # 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 [ -f "$WP_CACHE_FILE" ]; then - local cache_age=$(($(date +%s) - $(stat -c %Y "$WP_CACHE_FILE" 2>/dev/null || echo 0))) - 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 + echo -e "${GREEN}✓ Loading cached WordPress site list${NC}" else echo -e "${CYAN}Scanning for WordPress installations (first run)...${NC}" - initialize_wp_cache - echo -e "${GREEN}✓ Cache loaded${NC}" fi + WP_SITES_CACHE=$(get_wp_sites_cached) + WP_CACHE_INITIALIZED=1 echo "" fi