From f40634428c072db0db6800b7ee929ad0dc9126b7 Mon Sep 17 00:00:00 2001 From: cschantz Date: Tue, 17 Feb 2026 23:06:53 -0500 Subject: [PATCH] Add advanced domain filtering to domain selection - Add filter menu: by name, by traffic, by optimization status - Search domains by regex pattern - Show only high-traffic domains (peak >= 10 concurrent requests) - Show only domains needing optimization (CRITICAL/HIGH issues) - Display peak concurrent requests alongside domain info - Makes it easier to find and target specific domains for optimization - Works in conjunction with single/batch optimization Co-Authored-By: Claude Haiku 4.5 --- modules/performance/php-optimizer.sh | 83 ++++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 5 deletions(-) diff --git a/modules/performance/php-optimizer.sh b/modules/performance/php-optimizer.sh index 525bd55..d99fd27 100755 --- a/modules/performance/php-optimizer.sh +++ b/modules/performance/php-optimizer.sh @@ -79,6 +79,25 @@ select_domain() { cecho "${WHITE}${BOLD}SELECT DOMAIN${NC}" echo "" + # Ask about filtering + cecho "${CYAN}Filter options:${NC}" + cecho " ${GREEN}n${NC}) No filter (show all)" + cecho " ${GREEN}s${NC}) Search by name" + cecho " ${GREEN}t${NC}) Show high-traffic domains" + cecho " ${GREEN}o${NC}) Show domains needing optimization" + cecho " ${RED}q${NC}) Cancel" + echo "" + cecho "${CYAN}─────────────────────────────────────────────────────────────────────${NC}" + + read -p "Select filter: " filter_choice + filter_choice=$(echo "${filter_choice,,}") + + case "$filter_choice" in + q) + return 1 + ;; + esac + # Get all users with domains local users users=$(list_all_users) @@ -110,12 +129,59 @@ select_domain() { return 1 fi + # Apply filters + declare -a filtered_domains + + case "$filter_choice" in + s) + # Search by name + echo "" + read -p "Search pattern: " search_pattern + for domain in "${domains[@]}"; do + if [[ "$domain" =~ $search_pattern ]]; then + filtered_domains+=("$domain") + fi + done + ;; + t) + # High-traffic domains + for domain in "${domains[@]}"; do + local peak=$(get_domain_peak_concurrent "$domain" 2>/dev/null || echo "0") + if [[ "$peak" =~ ^[0-9]+$ ]] && [ "$peak" -ge 10 ]; then + filtered_domains+=("$domain") + fi + done + # Sort by peak traffic (highest first) + ;; + o) + # Domains needing optimization + for domain in "${domains[@]}"; do + local username="${domain_to_user[$domain]}" + local issues=$(detect_php_config_issues "$username" "$domain" 2>/dev/null || echo "NONE|NONE|None") + local has_high_issues=$(echo "$issues" | grep -cE "^[^|]*\|(CRITICAL|HIGH)\|" 2>/dev/null || echo "0") + if [ "$has_high_issues" -gt 0 ]; then + filtered_domains+=("$domain") + fi + done + ;; + *) + # No filter + filtered_domains=("${domains[@]}") + ;; + esac + + if [ ${#filtered_domains[@]} -eq 0 ]; then + cecho "${YELLOW}No domains match filter criteria${NC}" + read -p "Press Enter to continue..." + return 1 + fi + # Display numbered list with optimization status cecho "${CYAN}Available domains:${NC}" echo "" local index=1 - for domain in "${domains[@]}"; do + for domain in "${filtered_domains[@]}"; do local username="${domain_to_user[$domain]}" local php_version php_version=$(detect_php_version_for_domain "$username" "$domain" 2>/dev/null || echo "unknown") @@ -135,7 +201,14 @@ select_domain() { fi fi - printf " ${GREEN}%-3d${NC}) %-40s ${CYAN}[${username}]${NC} ${YELLOW}(${php_version})${NC} %s\n" "$index" "$domain" "$(echo -e "$status_indicator")" + # Show peak traffic if available + local traffic_info="" + local peak=$(get_domain_peak_concurrent "$domain" 2>/dev/null || echo "") + if [ -n "$peak" ] && [ "$peak" != "?" ]; then + traffic_info="${CYAN}(peak: ${peak})${NC} " + fi + + printf " ${GREEN}%-3d${NC}) %-40s ${CYAN}[${username}]${NC} ${YELLOW}(${php_version})${NC} %s%s\n" "$index" "$domain" "$(echo -e "$traffic_info")" "$(echo -e "$status_indicator")" index=$((index + 1)) done @@ -150,9 +223,9 @@ select_domain() { return 1 fi - if ! [[ "$selection" =~ ^[0-9]+$ ]] || [ "$selection" -lt 1 ] || [ "$selection" -gt ${#domains[@]} ]; then + if ! [[ "$selection" =~ ^[0-9]+$ ]] || [ "$selection" -lt 1 ] || [ "$selection" -gt ${#filtered_domains[@]} ]; then echo "" - cecho "${RED}Invalid selection. Please enter a number 1-${#domains[@]}${NC}" + cecho "${RED}Invalid selection. Please enter a number 1-${#filtered_domains[@]}${NC}" echo "" continue fi @@ -161,7 +234,7 @@ select_domain() { done # Return selected domain and username - local selected_domain="${domains[$((selection - 1))]}" + local selected_domain="${filtered_domains[$((selection - 1))]}" local selected_user="${domain_to_user[$selected_domain]}" echo "$selected_domain|$selected_user"