mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-10 07:05:02 +03:00
fix(traffic): stop adding capped counters in SQL
Per-client counters are stored up to TrafficMax, which a node can reach by reporting huge usage, and the group totals, group baselines and the per-client reset lookup added two such counters inside SQL, overflowing it: every group listing and reset failed, and no client on that reset cycle was reset. The counters are now read separately and added in Go, saturating at TrafficMax.
This commit is contained in:
@@ -152,3 +152,17 @@ func TestClientTrafficResetValidation(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// A node can report counters at TrafficMax; adding two in SQL overflowed and failed the
|
||||
// lookup, so no client on that cycle was reset at all.
|
||||
func TestGetClientsByTrafficResetSurvivesCountersAtTheCap(t *testing.T) {
|
||||
initTrafficTestDB(t)
|
||||
if err := database.GetDB().Create(&model.ClientRecord{Email: "huge", Enable: false, TrafficReset: "daily"}).Error; err != nil {
|
||||
t.Fatalf("seed client: %v", err)
|
||||
}
|
||||
seedClientRow(t, "huge", 1, database.TrafficMax, database.TrafficMax, 100)
|
||||
cycles, err := (&ClientService{}).GetClientsByTrafficReset("daily")
|
||||
if err != nil || len(cycles) != 1 || !cycles[0].Depleted() {
|
||||
t.Fatalf("GetClientsByTrafficReset = %+v, %v; want the client, depleted", cycles, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user