From 1c4f804738732508cc0f9456c9d75e201681ff39 Mon Sep 17 00:00:00 2001 From: ayflying Date: Mon, 17 Mar 2025 11:21:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8C=81=E4=B9=85=E5=8C=96?= =?UTF-8?q?=E7=9A=84=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/logic/gameAct/gameAct.go | 14 ++++---------- tools/random.go | 2 +- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/internal/logic/gameAct/gameAct.go b/internal/logic/gameAct/gameAct.go index b55384b..c39aff0 100644 --- a/internal/logic/gameAct/gameAct.go +++ b/internal/logic/gameAct/gameAct.go @@ -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) } //批量写入数据库 diff --git a/tools/random.go b/tools/random.go index b3f8c0c..a67afee 100644 --- a/tools/random.go +++ b/tools/random.go @@ -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()) // 复制权重映射,避免修改原始数据