diff --git a/modules/website/wordpress/wordpress-cron-manager.sh b/modules/website/wordpress/wordpress-cron-manager.sh index 7c82740..c4714f2 100755 --- a/modules/website/wordpress/wordpress-cron-manager.sh +++ b/modules/website/wordpress/wordpress-cron-manager.sh @@ -205,6 +205,7 @@ CRON_OFFSET=0 # Instead of running find 23 times, run once and reuse results declare -g WP_SITES_CACHE="" declare -g WP_CACHE_INITIALIZED=0 +declare -g WP_CACHE_FILE="/tmp/wp-sites-cache-$$" # OPTIMIZATION: Function Registry (OPT-14) # Maintains a registry of all available functions for discoverability and validation @@ -320,20 +321,40 @@ get_home_path() { # Runs once at script startup, results used by all subsequent functions initialize_wp_cache() { local panel="$SYS_CONTROL_PANEL" + + # Check if cache file already exists from earlier in this session + if [ -f "$WP_CACHE_FILE" ]; then + WP_SITES_CACHE=$(cat "$WP_CACHE_FILE") + WP_CACHE_INITIALIZED=1 + return + fi + + # Run the discovery and save to temp file for persistence WP_SITES_CACHE=$(get_wp_search_paths "$panel") + echo "$WP_SITES_CACHE" > "$WP_CACHE_FILE" 2>/dev/null WP_CACHE_INITIALIZED=1 } # Function to get cached WordPress installations # Returns cached results from initialize_wp_cache() +# Always returns instantly (uses file cache) get_wp_sites_cached() { - # Initialize cache if not already done + # Quick check: if we have the temp file, use it immediately (no discovery needed) + if [ -f "$WP_CACHE_FILE" ]; then + cat "$WP_CACHE_FILE" + return + fi + + # Fallback: Initialize cache if not already done if [ "$WP_CACHE_INITIALIZED" = "0" ]; then initialize_wp_cache fi echo "$WP_SITES_CACHE" } +# Cleanup cache on exit +trap 'rm -f "$WP_CACHE_FILE" "$LOCK_FILE"; rollback_cleanup' EXIT INT TERM + # OPTIMIZATION: User extraction caching (memoization) # extract_user_from_path() called 10 times, often for same path # Cache results to avoid redundant extraction operations