diff options
Diffstat (limited to 'web/service')
| -rw-r--r-- | web/service/xray.go | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/web/service/xray.go b/web/service/xray.go index 511ffdda..be140ce6 100644 --- a/web/service/xray.go +++ b/web/service/xray.go @@ -118,31 +118,35 @@ func (s *XrayService) GetXrayConfig() (*xray.Config, error) { json.Unmarshal([]byte(inbound.Settings), &settings) clients, ok := settings["clients"].([]any) if ok { - // check users active or not + // Fast O(N) lookup map for client traffic enablement clientStats := inbound.ClientStats + enableMap := make(map[string]bool, len(clientStats)) for _, clientTraffic := range clientStats { - indexDecrease := 0 - for index, client := range clients { - c := client.(map[string]any) - if c["email"] == clientTraffic.Email { - if !clientTraffic.Enable { - clients = RemoveIndex(clients, index-indexDecrease) - indexDecrease++ - logger.Infof("Remove Inbound User %s due to expiration or traffic limit", c["email"]) - } - } - } + enableMap[clientTraffic.Email] = clientTraffic.Enable } - // clear client config for additional parameters + // filter and clean clients var final_clients []any for _, client := range clients { - c := client.(map[string]any) - if c["enable"] != nil { - if enable, ok := c["enable"].(bool); ok && !enable { - continue - } + c, ok := client.(map[string]any) + if !ok { + continue } + + email, _ := c["email"].(string) + + // check users active or not via stats + if enable, exists := enableMap[email]; exists && !enable { + logger.Infof("Remove Inbound User %s due to expiration or traffic limit", email) + continue + } + + // check manual disabled flag + if manualEnable, ok := c["enable"].(bool); ok && !manualEnable { + continue + } + + // clear client config for additional parameters for key := range c { if key != "email" && key != "id" && key != "password" && key != "flow" && key != "method" { delete(c, key) |
