修复若干bug
This commit is contained in:
1 parent
ee49ef15b5
commit
244b4bd9fd
12 files changed
+329
-83
No files matched your search
@@ -124,9 +124,10 @@ func (c *BackendOperationLogController) List() {
|
||||
return
|
||||
}
|
||||
|
||||
userResolver := services.NewOperationLogUserResolver()
|
||||
list := make([]map[string]interface{}, 0, len(rows))
|
||||
for i := range rows {
|
||||
userAccount, userName := services.OperationLogUser(rows[i].Tid, rows[i].UserID)
|
||||
userAccount, userName := userResolver.Resolve(rows[i].Tid, rows[i].UserID)
|
||||
item := map[string]interface{}{
|
||||
"id": rows[i].ID,
|
||||
"tid": rows[i].Tid,
|
||||
|
||||
@@ -119,9 +119,10 @@ func (c *PlatformOperationLogController) List() {
|
||||
return
|
||||
}
|
||||
|
||||
userResolver := services.NewOperationLogUserResolver()
|
||||
list := make([]map[string]interface{}, 0, len(rows))
|
||||
for i := range rows {
|
||||
userAccount, userName := services.OperationLogUser(rows[i].Tid, rows[i].UserID)
|
||||
userAccount, userName := userResolver.Resolve(rows[i].Tid, rows[i].UserID)
|
||||
item := map[string]interface{}{
|
||||
"id": rows[i].ID,
|
||||
"tid": rows[i].Tid,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -436,16 +436,23 @@ func scanAndSendReminders() {
|
||||
for i := range list {
|
||||
reminder := &list[i]
|
||||
|
||||
// 3.1 获取日程信息(主要拿 Content,Title 统一为 "日程提醒")
|
||||
// 3.1 获取日程信息;消息内容统一拼接为【标题】内容,内容为空时用兜底文案,保证永远有提示内容
|
||||
var schedule models.BackendSchedule
|
||||
err := models.Orm.QueryTable(new(models.BackendSchedule)).
|
||||
Filter("id", reminder.ScheduleID).
|
||||
One(&schedule)
|
||||
title := "日程提醒"
|
||||
content := "您有一个待处理的日程时间已到,请注意查收。"
|
||||
body := ""
|
||||
if err == nil {
|
||||
content = schedule.Content
|
||||
if t := strings.TrimSpace(schedule.Title); t != "" {
|
||||
title = t
|
||||
}
|
||||
body = strings.TrimSpace(schedule.Content)
|
||||
}
|
||||
if body == "" {
|
||||
body = "您有一个待处理的日程时间已到,请注意查收。"
|
||||
}
|
||||
content := fmt.Sprintf("【%s】%s", title, body)
|
||||
|
||||
sender, ok := senders[reminder.RemindChannel]
|
||||
if !ok {
|
||||
|
||||
Reference in new issue
Block a user