mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6169] [MERGED] fix(clients): stop recomputing the summary badges from the client_stats snapshot #6131
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6131
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/6169
Author: @mrnickson-hue
Created: 8/1/2026
Status: ✅ Merged
Merged: 8/14/2026
Merged by: @MHSanaei
Base:
main← Head:fix/6116-client-summary-server-trust📝 Commits (2)
aa28148fix(clients): stop recomputing the summary badges from the client_stats snapshot81f7320fix(clients): force a refetch on window focus and drop a stale comment📊 Changes
4 files changed (+114 additions, -233 deletions)
View changed files
📝
frontend/src/hooks/useClients.ts(+3 -87)📝
frontend/src/pages/inbounds/useInbounds.ts(+0 -4)➖
frontend/src/test/clients-summary.test.ts(+0 -142)➕
frontend/src/test/clients-summary.test.tsx(+111 -0)📄 Description
Summary
Drops the client-side recompute in
pickClientsSummary(frontend/src/hooks/useClients.ts) that could display a corrupted clients-page summary when theclient_statsWS snapshot diverged fromclientsin a shape the coverage guard couldn't detect. The summary badges now always read the server'sq.summary()result directly.Why
Refs #6116.
pickClientsSummary's guard is a count comparison (serverSummary.total > allClientStats.length), not an identity/coverage check.allClientStatsis the rawclient_trafficstable (GetAllClientTraffics(), no join back toclients), so it can carry orphaned rows (traffic with no matching client) and can be missing rows for clients that don't have one yet. A shortfall-only guard misses two real cases: an orphan and a gap netting out to the same count, and — per #6116's bot review — an orphan surplus alone, which is the more reachable one since it needs drift in only one direction.Since #6116 was opened,
client_paging.go'sq.summary()(landed inf52c3c4, "make the clients page scale to large panels") already computes the same bucket counts as a bounded SQL aggregate withclientsas the driving table (Table("clients AS c").Joins("LEFT JOIN client_traffics ...")). That query can't confuse an orphanedclient_trafficsrow for a real client regardless of how or when the row got there — it's driven byclients, notclient_traffics. It's already shipped on every/panel/api/clients/list/pagedresponse, andlistQueryalready polls that endpoint every 5000ms (refetchInterval: 5000), which happens to matchcadenceXrayTraffic = "@every 5s"exactly.That means the "cheaper aggregate query" #6116's discussion was waiting on to justify a server-side summary already exists and already runs on a matching cadence — just over REST instead of the
client_statsWS payload. The client-side recompute this PR removes wasn't buying any extra freshness over that poll, only a window to get the number wrong. Dropping it needs no new backend work and, if anything, removes work from the hot path (computeClientsSummaryused to re-run on everyclient_statspush).Multi-node panels are, if anything, more exposed to the underlying divergence than a single-node install:
NodeTrafficSyncJobis a second, independent source ofclient_statsbroadcasts on its own@every 5stimer (not phase-locked to the local traffic job's), reading the same unjoinedGetAllClientTraffics(), andSetRemoteTrafficmerges up to 8 nodes' snapshots into the sharedclients/client_trafficstables concurrently.q.summary()'s correctness doesn't depend on that timing at all, since it always reflects whatever's actually in the database at request time.Mutation responsiveness (enable/disable/delete/etc.) is unaffected — those already call
invalidateAll(), which forces an immediatelistQueryrefetch independent of the 5s poll.Type of change
Areas affected
How was this tested?
frontend/src/test/clients-summary.test.tsx: two new tests reproduce #6116's exact shapes against the live hook (renderHook+applyClientStatsEvent) — an orphan row with no compensating gap, and an orphan+gap pair that nets to the server's total — and assertsummarystays pinned to the server's value in both, where the old guard let at least one of these through.allClientStats,computeClientsSummary,pickClientsSummaryandsameSummaryInputsare removed as dead code (their only caller was the recompute this PR drops);sameSpeedMap's tests are kept as-is since that function is unrelated and untouched.make verify(gen-check, golangci-lint, ESLint,tsc --noEmit,go test -shuffle=on -count=1 ./..., frontendnpm run test,go build ./...+ frontend build,build-storybook) — all green except two pre-existing, unrelatedclient-form-flow.test.tsx/inbound-form-modal.test.tsxtimeouts under this sandbox's load, which I confirmed also fail on an unmodifiedmaincheckout (git stash+ rerun) before restoring this change, so they're not a regression from this diff.Screenshots / recordings
N/A — no visual change, the displayed numbers are unaffected in the common case; this only changes what happens during the specific divergence window #6116 describes.
Breaking changes
None.
Checklist
go build ./...and the test suite pass locally.npm run lint,npm run typecheck, andnpm run buildpass.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.