all: imp docs

This commit is contained in:
Stanislav Chzhen 2023-02-27 17:12:20 +03:00
parent 8fb7e7349d
commit d7db0a5af1
3 changed files with 9 additions and 9 deletions

View File

@ -7,7 +7,6 @@ import (
"net" "net"
"net/http" "net/http"
"net/url" "net/url"
"sort"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -18,6 +17,7 @@ import (
"github.com/AdguardTeam/golibs/log" "github.com/AdguardTeam/golibs/log"
"github.com/AdguardTeam/golibs/stringutil" "github.com/AdguardTeam/golibs/stringutil"
"github.com/AdguardTeam/golibs/timeutil" "github.com/AdguardTeam/golibs/timeutil"
"golang.org/x/exp/slices"
"golang.org/x/net/idna" "golang.org/x/net/idna"
) )
@ -127,7 +127,7 @@ func (l *queryLog) handleGetQueryLogConfig(w http.ResponseWriter, r *http.Reques
defer l.lock.Unlock() defer l.lock.Unlock()
ignored := l.conf.Ignored.Values() ignored := l.conf.Ignored.Values()
sort.Strings(ignored) slices.Sort(ignored)
_ = aghhttp.WriteJSONResponse(w, r, getConfigResp{ _ = aghhttp.WriteJSONResponse(w, r, getConfigResp{
Enabled: aghalg.BoolToNullBool(l.conf.Enabled), Enabled: aghalg.BoolToNullBool(l.conf.Enabled),
Interval: float64(l.conf.RotationIvl.Milliseconds()), Interval: float64(l.conf.RotationIvl.Milliseconds()),

View File

@ -5,7 +5,6 @@ package stats
import ( import (
"encoding/json" "encoding/json"
"net/http" "net/http"
"sort"
"time" "time"
"github.com/AdguardTeam/AdGuardHome/internal/aghalg" "github.com/AdguardTeam/AdGuardHome/internal/aghalg"
@ -13,6 +12,7 @@ import (
"github.com/AdguardTeam/AdGuardHome/internal/aghnet" "github.com/AdguardTeam/AdGuardHome/internal/aghnet"
"github.com/AdguardTeam/golibs/log" "github.com/AdguardTeam/golibs/log"
"github.com/AdguardTeam/golibs/timeutil" "github.com/AdguardTeam/golibs/timeutil"
"golang.org/x/exp/slices"
) )
// topAddrs is an alias for the types of the TopFoo fields of statsResponse. // 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) _ = aghhttp.WriteJSONResponse(w, r, resp)
} }
// handleGetStatsConfig handles requests to the GET /control/stats_info // handleGetStatsConfig handles requests to the GET /control/stats/config
// endpoint. // endpoint.
func (s *StatsCtx) handleGetStatsConfig(w http.ResponseWriter, r *http.Request) { func (s *StatsCtx) handleGetStatsConfig(w http.ResponseWriter, r *http.Request) {
s.lock.Lock() s.lock.Lock()
defer s.lock.Unlock() defer s.lock.Unlock()
ignored := s.ignored.Values() ignored := s.ignored.Values()
sort.Strings(ignored) slices.Sort(ignored)
resp := getConfigResp{ resp := getConfigResp{
Enabled: aghalg.BoolToNullBool(s.enabled), Enabled: aghalg.BoolToNullBool(s.enabled),
@ -150,8 +150,8 @@ func (s *StatsCtx) handleStatsConfig(w http.ResponseWriter, r *http.Request) {
s.setLimitLocked(int(reqData.IntervalDays)) s.setLimitLocked(int(reqData.IntervalDays))
} }
// handlePutStatsConfig handles requests to the PUT /control/stats_config // handlePutStatsConfig handles requests to the PUT
// endpoint. // /control/stats/config/update endpoint.
func (s *StatsCtx) handlePutStatsConfig(w http.ResponseWriter, r *http.Request) { func (s *StatsCtx) handlePutStatsConfig(w http.ResponseWriter, r *http.Request) {
reqData := getConfigResp{} reqData := getConfigResp{}
err := json.NewDecoder(r.Body).Decode(&reqData) err := json.NewDecoder(r.Body).Decode(&reqData)

View File

@ -43,8 +43,7 @@ type Config struct {
// Filename is the name of the database file. // Filename is the name of the database file.
Filename string Filename string
// Limit is an upper limit for collecting statistics into the // Limit is an upper limit for collecting statistics.
// current unit.
Limit time.Duration Limit time.Duration
// Enabled tells if the statistics are enabled. // Enabled tells if the statistics are enabled.
@ -537,6 +536,7 @@ func (s *StatsCtx) loadUnits(limit uint32) (units []*unitDB, firstID uint32) {
// Per-hour units. // Per-hour units.
units = make([]*unitDB, 0, limit) units = make([]*unitDB, 0, limit)
firstID = curID - limit + 1 firstID = curID - limit + 1
for i := firstID; i != curID; i++ { for i := firstID; i != curID; i++ {
u := loadUnitFromDB(tx, i) u := loadUnitFromDB(tx, i)
if u == nil { if u == nil {