Pull request 2302: upd-all

Squashed commit of the following:

commit f920006277f39b74c803139af2a9039aa45effae
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Fri Nov 8 16:14:41 2024 +0300

    all: fix pre-commit; upd dnsproxy

commit 391f79b244348c6075f5ba0fccfb8882791bf3f1
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Thu Nov 7 18:53:28 2024 +0300

    scripts: imp install

commit 35324db80b591831c32b7ea45930eefee82a6320
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Thu Nov 7 18:20:23 2024 +0300

    all: imp docs, scripts

commit d2724cfaefdb8659efbdb5bf181a28721a909f07
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Thu Nov 7 17:26:23 2024 +0300

    all: upd go, deps, tools, scripts
This commit is contained in:
Ainar Garipov
2024-11-08 17:18:16 +03:00
parent 6673bb175a
commit ac5a96fada
40 changed files with 834 additions and 916 deletions

View File

@@ -5,6 +5,7 @@ import (
"encoding/binary"
"encoding/gob"
"fmt"
"maps"
"slices"
"time"
@@ -12,7 +13,6 @@ import (
"github.com/AdguardTeam/golibs/errors"
"github.com/AdguardTeam/golibs/logutil/slogutil"
"go.etcd.io/bbolt"
"golang.org/x/exp/maps"
)
const (
@@ -234,18 +234,15 @@ func (a countPair) compareCount(b countPair) (res int) {
}
}
func convertMapToSlice(m map[string]uint64, max int) (s []countPair) {
func convertMapToSlice(m map[string]uint64, maxVal int) (s []countPair) {
s = make([]countPair, 0, len(m))
for k, v := range m {
s = append(s, countPair{Name: k, Count: v})
}
slices.SortFunc(s, countPair.compareCount)
if max > len(s) {
max = len(s)
}
return s[:max]
return s[:min(maxVal, len(s))]
}
func convertSliceToMap(a []countPair) (m map[string]uint64) {
@@ -611,9 +608,7 @@ func microsecondsToSeconds(n float64) (r float64) {
func prepareTopUpstreamsAvgTime(
upstreamsAvgTime topAddrsFloat,
) (topUpstreamsAvgTime []topAddrsFloat) {
keys := maps.Keys(upstreamsAvgTime)
slices.SortFunc(keys, func(a, b string) (res int) {
keys := slices.SortedStableFunc(maps.Keys(upstreamsAvgTime), func(a, b string) (res int) {
switch x, y := upstreamsAvgTime[a], upstreamsAvgTime[b]; {
case x > y:
return -1