Use atomic value for initial traffic
This commit is contained in:
@@ -198,8 +198,8 @@ func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) {
|
||||
}
|
||||
efficiency := response.ServedMB * 100 / denominator
|
||||
|
||||
if zr.initialTraffic > response.TrafficLogged {
|
||||
zr.initialTraffic = response.TrafficLogged
|
||||
if zr.initialTraffic.Load() > response.TrafficLogged {
|
||||
zr.initialTraffic.Store(response.TrafficLogged)
|
||||
}
|
||||
|
||||
out += fmt.Sprintf(`
|
||||
@@ -250,7 +250,7 @@ func (zr *Handlers) handleHome(resp http.ResponseWriter, req *http.Request) {
|
||||
response.NumGC,
|
||||
response.PID,
|
||||
response.TrafficLogged,
|
||||
response.TrafficLogged-bToMb(uint64(zr.initialTraffic)),
|
||||
response.TrafficLogged-bToMb(zr.initialTraffic.Load()),
|
||||
response.RequestedMB,
|
||||
response.ServedMB,
|
||||
efficiency,
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/debridmediamanager/zurg/internal/config"
|
||||
"github.com/debridmediamanager/zurg/internal/dav"
|
||||
@@ -26,7 +27,7 @@ type Handlers struct {
|
||||
api *realdebrid.RealDebrid
|
||||
workerPool *ants.Pool
|
||||
hosts []string
|
||||
initialTraffic uint64
|
||||
initialTraffic atomic.Uint64
|
||||
log *logutil.Logger
|
||||
}
|
||||
|
||||
@@ -52,9 +53,9 @@ func AttachHandlers(router *chi.Mux, downloader *universal.Downloader, torMgr *t
|
||||
log.Errorf("Failed to get traffic details: %v", err)
|
||||
trafficDetails = make(map[string]int64)
|
||||
}
|
||||
hs.initialTraffic = 0
|
||||
hs.initialTraffic.Store(uint64(0))
|
||||
if _, ok := trafficDetails["real-debrid.com"]; ok {
|
||||
hs.initialTraffic = uint64(trafficDetails["real-debrid.com"])
|
||||
hs.initialTraffic.Store(uint64(trafficDetails["real-debrid.com"]))
|
||||
}
|
||||
|
||||
if cfg.GetUsername() != "" {
|
||||
|
||||
Reference in New Issue
Block a user