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
+15 -10
View File
@@ -50,17 +50,22 @@ func (s *ClientService) ResetTrafficByEmail(inboundSvc *InboundService, email st
needRestart = nr
}
// Enable only a client the quota switched off, once the counters are zero: a
// hand-disabled one stays off, and a still-depleted one would be switched off again.
// Restore quota-disabled clients after zeroing; preserve an operator
// disable, including when no inbound remains.
if !rec.Enable && len(quotaDisabled) > 0 {
updated := rec.ToClient()
updated.Enable = true
nr, uErr := s.Update(inboundSvc, rec.Id, *updated, rec.LimitHwid)
if uErr != nil {
logger.Warning("Failed to auto-enable client during traffic reset:", uErr)
}
if nr {
needRestart = true
// Inbound resets already restored hosted clients. Only an unhosted
// record still needs the full update.
fresh, fErr := s.GetRecordByEmail(nil, email)
if fErr == nil && !fresh.Enable {
updated := fresh.ToClient()
updated.Enable = true
nr, uErr := s.Update(inboundSvc, fresh.Id, *updated, fresh.LimitHwid)
if uErr != nil {
logger.Warning("Failed to auto-enable client during traffic reset:", uErr)
}
if nr {
needRestart = true
}
}
}
return needRestart, nil