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