fix: Align Option 5 optimizer with batch analyzer traffic metrics

CRITICAL ALIGNMENT FIX
Option 5 (Optimize Server-Wide) was NOT using the same traffic percentage
calculation as the batch analyzer. It had the SAME BUG we just fixed:
passing per-user domains instead of ALL server domains.

What was fixed:
1. Added pre-collection loop (lines 2497-2515) to gather all domains
   • Same approach as batch analyzer
   • Builds all_domains_string before processing

2. Updated traffic calculation (line 2544)
   • OLD: get_domain_traffic_percentage(..., $user_domains)
   • NEW: get_domain_traffic_percentage(..., $all_domains_string)

Result: NOW ALIGNED WITH BATCH ANALYZER
✓ Option 5 uses ACTUAL memory per process (140MB)
✓ Option 5 uses CORRECT traffic percentages (all domains)
✓ Option 5 uses THREE-CONSTRAINT intelligent model
✓ Option 5 has SAME safety validation

When user selects Option 5, they WILL get same metrics as analysis.
This commit is contained in:
Developer
2026-04-20 18:19:36 -04:00
parent ef993c1bc6
commit 94c486717f
+14 -1
View File
@@ -2494,6 +2494,18 @@ optimize_level_5_everything() {
local users
users=$(list_all_users)
# CRITICAL FIX: Build list of ALL domains on server FIRST
# This is needed for accurate traffic percentage calculation (same as batch analyzer)
all_domains_string=""
while IFS= read -r u; do
[ -z "$u" ] && continue
u_domains=$(get_user_domains "$u")
while IFS= read -r d; do
[ -z "$d" ] && continue
all_domains_string="$all_domains_string$d"$'\n'
done <<< "$u_domains"
done <<< "$users"
while IFS= read -r username; do
[ -z "$username" ] && continue
local user_domains
@@ -2527,7 +2539,8 @@ optimize_level_5_everything() {
recommended_requests=$(get_max_requests_recommendation "$domain")
else
# Use intelligent three-constraint model
traffic_pct=$(get_domain_traffic_percentage "$username" "$domain" "$user_domains" 2>/dev/null | cut -d'|' -f1)
# CRITICAL FIX: Pass ALL server domains, not just user's domains!
traffic_pct=$(get_domain_traffic_percentage "$username" "$domain" "$all_domains_string" 2>/dev/null | cut -d'|' -f1)
traffic_pct=${traffic_pct:-50}
# Call intelligent three-constraint function