修改持久化的顺序

This commit is contained in:
ayflying
2025-03-17 11:21:37 +08:00
parent 5fbe4d5dcf
commit 1c4f804738
2 changed files with 5 additions and 11 deletions

View File

@@ -138,14 +138,13 @@ func (s *sGameAct) Save(actId int) (err error) {
}
cacheGet, _ := g.Redis().Get(ctx, cacheKey)
//最后删除key
delKey = append(delKey, cacheKey)
if uid == 0 {
//跳过为空的用户缓存
continue
}
if cacheGet.IsEmpty() {
//空数据也不保存
//空数据也不保存
continue
}
@@ -155,12 +154,6 @@ func (s *sGameAct) Save(actId int) (err error) {
continue
}
////如果1天没有活跃跳过
//user, _ := service.MemberUser().Info(uid)
//if user.UpdatedAt.Seconds < gtime.Now().Add(consts.ActSaveTime).Unix() {
// continue
//}
//获取数据库数据
var data *entity.GameAct
// 从数据库中查询活动信息
@@ -185,7 +178,8 @@ func (s *sGameAct) Save(actId int) (err error) {
data.Action = actionData
add = append(add, data)
}
//最后删除key
delKey = append(delKey, cacheKey)
}
//批量写入数据库

View File

@@ -15,7 +15,7 @@ type randMod struct {
// RandomAll 按权重随机选取 N 个不重复的元素
func (m *randMod) RandomAll(data map[int]int, n int) []int {
if n > len(data) {
return nil
n = len(data)
}
rand.Seed(time.Now().UnixNano())
// 复制权重映射,避免修改原始数据