fix: Calculate traffic percentage against ALL server domains, not just per-user domains

CRITICAL BUG - Traffic Percentage Calculation
The batch analyzer was comparing each domain against only that user's domains,
not against all domains on the server. This caused completely inverted traffic
percentages:
  - Single-domain users showed 100% traffic (wrong!)
  - Traffic percentages were meaningless
  - Fair share allocation was incorrect

Root Cause:
  Line 160 passed $user_domains (one user's domains) instead of ALL domains

Fix:
  1. Added pre-processing loop (lines 97-105) to collect ALL domains first
  2. Store all domains in $all_domains_string (newline-delimited)
  3. Pass $all_domains_string to get_domain_traffic_percentage() instead of $user_domains

Impact on user's 8GB server:
  BEFORE:
    abortionpillnyc.com: 421 requests shown as 2% of server (WRONG!)
    parkmed.com: 2 requests shown as 100% of server (WRONG!)
  AFTER:
    abortionpillnyc.com: 421 requests = 99% of server (CORRECT!)
    parkmed.com: 2 requests = 1% of server (CORRECT!)

Fair share allocation now correctly gives more capacity to high-traffic domains.
This commit is contained in:
Developer
2026-04-20 18:09:34 -04:00
parent e2fca67df2
commit 2ab02fdc50
+15 -1
View File
@@ -91,6 +91,19 @@ cecho "${CYAN}──────────────────────
# Get all users and domains
users=$(list_all_users)
# CRITICAL FIX: Build list of ALL domains on server FIRST
# This is needed for accurate traffic percentage calculation
declare -a all_server_domains
local all_domains_string=""
while IFS= read -r username; do
[ -z "$username" ] && continue
user_domains=$(get_user_domains "$username")
while IFS= read -r domain; do
[ -z "$domain" ] && continue
all_domains_string="$all_domains_string$domain"$'\n'
done <<< "$user_domains"
done <<< "$users"
# Initialize tracking arrays
declare -a domain_list
declare -a domain_owner
@@ -157,7 +170,8 @@ while IFS= read -r username; do
# Calculate recommended using THREE-CONSTRAINT INTELLIGENT ALGORITHM
# Get traffic percentage for this domain
traffic_percentage=$(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_percentage=$(get_domain_traffic_percentage "$username" "$domain" "$all_domains_string" 2>/dev/null | cut -d'|' -f1)
traffic_percentage=${traffic_percentage:-50}
# Use intelligent three-constraint model: MIN(memory, traffic, fair_share)