perf(admin): optimize large-dataset loading for dashboard/users/accounts/ops

This commit is contained in:
xvhuan
2026-03-04 13:45:49 +08:00
parent 46ea9170cb
commit 80ae592c23
27 changed files with 1109 additions and 179 deletions

View File

@@ -0,0 +1,46 @@
package admin
import (
"sort"
"strconv"
"strings"
"time"
)
var accountTodayStatsBatchCache = newSnapshotCache(30 * time.Second)
func normalizeAccountIDList(accountIDs []int64) []int64 {
if len(accountIDs) == 0 {
return nil
}
seen := make(map[int64]struct{}, len(accountIDs))
out := make([]int64, 0, len(accountIDs))
for _, id := range accountIDs {
if id <= 0 {
continue
}
if _, ok := seen[id]; ok {
continue
}
seen[id] = struct{}{}
out = append(out, id)
}
sort.Slice(out, func(i, j int) bool { return out[i] < out[j] })
return out
}
func buildAccountTodayStatsBatchCacheKey(accountIDs []int64) string {
if len(accountIDs) == 0 {
return "accounts_today_stats_empty"
}
var b strings.Builder
b.Grow(len(accountIDs) * 6)
b.WriteString("accounts_today_stats:")
for i, id := range accountIDs {
if i > 0 {
b.WriteByte(',')
}
b.WriteString(strconv.FormatInt(id, 10))
}
return b.String()
}