修复若干bug

This commit is contained in:
hero920103 committed 2026-11-09 11:42:23 +08:00
1 parent ee49ef15b5
commit 244b4bd9fd
12 files changed
+329 -83

No files matched your search

+30
View File
@@ -37,3 +37,33 @@ func OperationLogUser(tid *uint64, userID uint64) (account, name string) {
}
return account, name
}
type operationLogUserKey struct {
tid uint64
uid uint64
}
// OperationLogUserResolver 请求级缓存的操作人解析器。
// 日志列表逐行调用 OperationLogUser 时,同一 (tid,userID) 会重复执行
// FindLegacyUID + 用户表查询(N+1),用它按键去重后每个用户只查一次。
type OperationLogUserResolver struct {
cache map[operationLogUserKey][2]string
}
func NewOperationLogUserResolver() *OperationLogUserResolver {
return &OperationLogUserResolver{cache: make(map[operationLogUserKey][2]string)}
}
func (r *OperationLogUserResolver) Resolve(tid *uint64, userID uint64) (account, name string) {
var tidVal uint64
if tid != nil {
tidVal = *tid
}
key := operationLogUserKey{tid: tidVal, uid: userID}
if v, ok := r.cache[key]; ok {
return v[0], v[1]
}
account, name = OperationLogUser(tid, userID)
r.cache[key] = [2]string{account, name}
return account, name
}