diff --git a/internal/querylog/http.go b/internal/querylog/http.go index 0b6976e0..1f5496bb 100644 --- a/internal/querylog/http.go +++ b/internal/querylog/http.go @@ -7,7 +7,6 @@ import ( "net" "net/http" "net/url" - "sort" "strconv" "strings" "time" @@ -18,6 +17,7 @@ import ( "github.com/AdguardTeam/golibs/log" "github.com/AdguardTeam/golibs/stringutil" "github.com/AdguardTeam/golibs/timeutil" + "golang.org/x/exp/slices" "golang.org/x/net/idna" ) @@ -127,7 +127,7 @@ func (l *queryLog) handleGetQueryLogConfig(w http.ResponseWriter, r *http.Reques defer l.lock.Unlock() ignored := l.conf.Ignored.Values() - sort.Strings(ignored) + slices.Sort(ignored) _ = aghhttp.WriteJSONResponse(w, r, getConfigResp{ Enabled: aghalg.BoolToNullBool(l.conf.Enabled), Interval: float64(l.conf.RotationIvl.Milliseconds()), diff --git a/internal/stats/http.go b/internal/stats/http.go index 2496e5e2..7e882380 100644 --- a/internal/stats/http.go +++ b/internal/stats/http.go @@ -5,7 +5,6 @@ package stats import ( "encoding/json" "net/http" - "sort" "time" "github.com/AdguardTeam/AdGuardHome/internal/aghalg" @@ -13,6 +12,7 @@ import ( "github.com/AdguardTeam/AdGuardHome/internal/aghnet" "github.com/AdguardTeam/golibs/log" "github.com/AdguardTeam/golibs/timeutil" + "golang.org/x/exp/slices" ) // topAddrs is an alias for the types of the TopFoo fields of statsResponse. @@ -103,14 +103,14 @@ func (s *StatsCtx) handleStatsInfo(w http.ResponseWriter, r *http.Request) { _ = aghhttp.WriteJSONResponse(w, r, resp) } -// handleGetStatsConfig handles requests to the GET /control/stats_info +// handleGetStatsConfig handles requests to the GET /control/stats/config // endpoint. func (s *StatsCtx) handleGetStatsConfig(w http.ResponseWriter, r *http.Request) { s.lock.Lock() defer s.lock.Unlock() ignored := s.ignored.Values() - sort.Strings(ignored) + slices.Sort(ignored) resp := getConfigResp{ Enabled: aghalg.BoolToNullBool(s.enabled), @@ -150,8 +150,8 @@ func (s *StatsCtx) handleStatsConfig(w http.ResponseWriter, r *http.Request) { s.setLimitLocked(int(reqData.IntervalDays)) } -// handlePutStatsConfig handles requests to the PUT /control/stats_config -// endpoint. +// handlePutStatsConfig handles requests to the PUT +// /control/stats/config/update endpoint. func (s *StatsCtx) handlePutStatsConfig(w http.ResponseWriter, r *http.Request) { reqData := getConfigResp{} err := json.NewDecoder(r.Body).Decode(&reqData) diff --git a/internal/stats/stats.go b/internal/stats/stats.go index 3254e9ed..82a14374 100644 --- a/internal/stats/stats.go +++ b/internal/stats/stats.go @@ -43,8 +43,7 @@ type Config struct { // Filename is the name of the database file. Filename string - // Limit is an upper limit for collecting statistics into the - // current unit. + // Limit is an upper limit for collecting statistics. Limit time.Duration // Enabled tells if the statistics are enabled. @@ -537,6 +536,7 @@ func (s *StatsCtx) loadUnits(limit uint32) (units []*unitDB, firstID uint32) { // Per-hour units. units = make([]*unitDB, 0, limit) firstID = curID - limit + 1 + for i := firstID; i != curID; i++ { u := loadUnitFromDB(tx, i) if u == nil {