mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-10-26 07:44:59 +03:00
perf(traffic): skip unchanged global writes between heartbeats (#6931)
* perf(traffic): skip unchanged global writes between heartbeats Persist directional usage changes immediately, including lower resets, while refreshing identical global totals only at an inclusive one-hour heartbeat. Use the GORM clock consistently for the existing 24-hour freshness window and preserve local-only snapshots, quota enforcement, and downstream forwarding. Fixes #6928 * docs(traffic): describe persisted global heartbeat timestamps Replace the stale every-push model comment with the change-or-hourly-heartbeat rule. Keep the local-counter separation, delta accounting, MAX fold and reset semantics explicit without treating UpdatedAt as a last-push timestamp. Address the nonblocking review feedback on PR #6931 without rewriting published history. Refs #6928
This commit is contained in:
@@ -1,15 +1,7 @@
|
||||
package model
|
||||
|
||||
// ClientGlobalTraffic mirrors a master panel's aggregated (global) usage for a
|
||||
// client hosted on this panel. Masters push one row per (master, email) so the
|
||||
// node can display the client's true cross-panel total and enforce its quota
|
||||
// locally. The values never feed back into client_traffics — that table keeps
|
||||
// this panel's local-only counters, which is what keeps every master's
|
||||
// delta-baseline accounting over our snapshot correct.
|
||||
//
|
||||
// Rows are overwritten in place on every push (not max-merged), so a traffic
|
||||
// reset on the master propagates here within one push cycle. Readers that need
|
||||
// a single number fold the per-master rows with MAX.
|
||||
// ClientGlobalTraffic separates each master's aggregate from local client_traffics for delta accounting; readers fold with MAX.
|
||||
// Changed totals (including resets) overwrite on the next push; UpdatedAt tracks changes or hourly unchanged heartbeats.
|
||||
type ClientGlobalTraffic struct {
|
||||
Id int `json:"id" gorm:"primaryKey;autoIncrement"`
|
||||
MasterGuid string `json:"masterGuid" gorm:"uniqueIndex:idx_master_email,priority:1;not null"`
|
||||
|
||||
Reference in New Issue
Block a user