refactor: 消除重复的 normalizeAccountIDList,补充 PR#754 新增组件的单元测试

- 删除 account_today_stats_cache.go 中重复的 normalizeAccountIDList,统一使用 id_list_utils.go 的 normalizeInt64IDList
- 新增 snapshot_cache_test.go:覆盖 snapshotCache、buildETagFromAny、parseBoolQueryWithDefault
- 新增 id_list_utils_test.go:覆盖 normalizeInt64IDList、buildAccountTodayStatsBatchCacheKey
- 新增 ops_query_mode_test.go:覆盖 shouldFallbackOpsPreagg、cloneOpsFilterWithMode
This commit is contained in:
shaw
2026-03-04 15:22:46 +08:00
parent 9dcd3cd491
commit 0819c8a51a
5 changed files with 252 additions and 22 deletions

View File

@@ -1,7 +1,6 @@
package admin
import (
"sort"
"strconv"
"strings"
"time"
@@ -9,26 +8,6 @@ import (
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"