mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-09-02 00:17:13 +00:00
fix(sub): recover {{TRAFFIC_USED}} for clients with orphaned traffic rows
statsForClient resolved usage only through paths keyed by client_traffics.inbound_id (preloaded ClientStats + the statsByEmail index). That id is written once by AddClientStat and never updated, so an inbound delete+recreate orphans the row from every loaded inbound, both paths miss, and the zero-traffic placeholder makes {{TRAFFIC_USED}} read 0.00B for pre-existing clients while the sub-info header (AggregateTrafficByEmails, email-keyed) stays correct.
Add a last-resort lookup by the globally-unique email, cached into statsByEmail for the request. Closes #5567.
This commit is contained in:
@@ -441,6 +441,13 @@ func (s *SubService) statsForClient(inbound *model.Inbound, client model.Client)
|
||||
if stats, ok := s.statsByEmail[client.Email]; ok {
|
||||
return stats
|
||||
}
|
||||
// Both in-memory paths key off client_traffics.inbound_id, which goes stale
|
||||
// when an inbound is deleted and recreated, orphaning the row from every
|
||||
// loaded inbound. Fall back to a direct lookup by the globally-unique email
|
||||
// so usage still resolves for clients predating that recreation (#5567).
|
||||
if stats, ok := s.statsByEmailFromDB(client.Email); ok {
|
||||
return stats
|
||||
}
|
||||
return xray.ClientTraffic{
|
||||
Enable: client.Enable,
|
||||
ExpiryTime: client.ExpiryTime,
|
||||
|
||||
Reference in New Issue
Block a user