mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-09-23 02:06:34 +08:00
Use efficient APIs and simplify loops
Minor refactors across the codebase to improve readability and use more efficient APIs: replace fmt.Sprintf+base64 encoding with fmt.Appendf when building Shadowsocks userInfo; compute elapsed using max(now-prev.at, window) to simplify logic; use strings.SplitSeq for splitting in two places; simplify test and goroutine loops to range-based iterations and use errgroup's Go helper; and align/clean up struct field formatting and test map literals. Mostly stylistic/efficiency changes with no intended behavior changes.
This commit is contained in:
@@ -246,10 +246,7 @@ func (j *NodeTrafficSyncJob) nodeInboundSpeed() []*xray.Traffic {
|
||||
if dDown < 0 {
|
||||
dDown = 0
|
||||
}
|
||||
elapsed := now - prev.at
|
||||
if elapsed < nodeInboundSpeedWindowMs {
|
||||
elapsed = nodeInboundSpeedWindowMs
|
||||
}
|
||||
elapsed := max(now-prev.at, nodeInboundSpeedWindowMs)
|
||||
up := dUp * nodeInboundSpeedWindowMs / elapsed
|
||||
down := dDown * nodeInboundSpeedWindowMs / elapsed
|
||||
if up > 0 || down > 0 {
|
||||
|
||||
Reference in New Issue
Block a user