fix(clients): restore depleted clients on renewal and prioritize operator writes (#6987)

Restore usable clients when renewed, avoid duplicate reset updates, and prioritize operator writes in the serialized traffic writer. Preserve manual disables and keep every inbound consistent after traffic resets.
This commit is contained in:
Mahdi Fallahnejhad
2026-11-05 20:37:52 +03:30
committed by GitHub
parent e4935be861
commit dbb6212988
13 changed files with 684 additions and 92 deletions
+28 -1
View File
@@ -1537,9 +1537,31 @@ func (s *ClientService) ResetClientIpLimitByEmail(inboundSvc *InboundService, cl
})
}
// renewalReenableFor projects the post-renewal limits for a single-field
// renewal (nil side keeps the stored limit; no row means no quota state).
func (s *ClientService) renewalReenableFor(email string, setExpiry *int64, setTotal *int64) bool {
total, expiry, ok := storedTrafficLimits(email)
if !ok {
return false
}
if setExpiry != nil {
expiry = *setExpiry
}
if setTotal != nil {
total = *setTotal
}
return s.renewalReenables(email, total, expiry)
}
func (s *ClientService) ResetClientExpiryTimeByEmail(inboundSvc *InboundService, clientEmail string, expiry_time int64) (bool, error) {
reenable := s.renewalReenableFor(clientEmail, &expiry_time, nil)
return s.applyClientFieldByEmail(inboundSvc, clientEmail, func(c map[string]any) {
c["expiryTime"] = expiry_time
if reenable {
// A renewed client that the quota loop had switched off comes back
// with the renewal instead of waiting for a manual enable (#5619).
c["enable"] = true
}
})
}
@@ -1547,7 +1569,12 @@ func (s *ClientService) ResetClientTrafficLimitByEmail(inboundSvc *InboundServic
if totalGB < 0 {
return false, common.NewError("totalGB must be >= 0")
}
newTotal := int64(totalGB) * 1024 * 1024 * 1024
reenable := s.renewalReenableFor(clientEmail, nil, &newTotal)
return s.applyClientFieldByEmail(inboundSvc, clientEmail, func(c map[string]any) {
c["totalGB"] = totalGB * 1024 * 1024 * 1024
c["totalGB"] = newTotal
if reenable {
c["enable"] = true
}
})
}