feat(stats): add bounded path and hash-width analytics (#159)

This commit is contained in:
n30nex authored and GitHub committed 2026-09-23 20:18:41 -04:00
1 parent 6107578c25
commit 8a3fa7e6bf
25 files changed
+1205 -4

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
// Copyright 2026 Beacon Contributors
// SPDX-License-Identifier: AGPL-3.0-or-later
package cache
import (
"context"
"encoding/json"
"fmt"
"slices"
"time"
"github.com/MeshCore-Beacon/beacon-server/internal/api"
)
func (cr *CachedReader) GetPathStats(ctx context.Context, since, until time.Time, iatas []string) (*api.PathStats, error) {
sorted := append([]string{}, iatas...)
slices.Sort(sorted)
sorted = slices.Compact(sorted)
segment, _ := json.Marshal(sorted) // [] and [""] must remain distinct (global vs empty region).
key := fmt.Sprintf("%s%s:%d:%d", keyPathStatsPrefix, segment, since.UnixMilli(), until.UnixMilli())
return getOrSet(ctx, cr.c, key, cr.ttl.Stats, func() (*api.PathStats, error) {
return cr.inner.GetPathStats(ctx, since, until, iatas)
})
}