From 8c60a1f6c7a8f03111bba38e66c88c90b24306bb Mon Sep 17 00:00:00 2001 From: ayflying Date: Wed, 3 Sep 2025 11:14:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=A7=E8=A1=8C=E9=80=9A=E9=81=93=E8=BF=9B?= =?UTF-8?q?=E5=85=A5=E5=8D=8F=E7=A8=8B=EF=BC=8C=E9=A2=84=E9=98=B2=E6=8B=A5?= =?UTF-8?q?=E5=A0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/logic/gameAct/gameAct.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/internal/logic/gameAct/gameAct.go b/internal/logic/gameAct/gameAct.go index 83242db..fb43a1a 100644 --- a/internal/logic/gameAct/gameAct.go +++ b/internal/logic/gameAct/gameAct.go @@ -315,7 +315,8 @@ func (s *sGameAct) SavesV2() (err error) { close(updateChan) }() // 启动缓存数据到数据库通道 - s.Cache2SqlChan(ctx) + go s.Cache2AddChan(ctx) + go s.Cache2UpdateChan(ctx) return } @@ -449,12 +450,12 @@ func (s *sGameAct) Cache2Sql(ctx context.Context, add, update []*entity.GameAct) return } -// Cache2SqlChan 缓存持久化到数据库 +// Cache2UpdateChan 缓存持久化到数据库 // @Description: 缓存持久化到数据库 // @receiver s *sGameAct: 游戏活动服务结构体指针 // @param ctx context.Context: 上下文对象 -func (s *sGameAct) Cache2SqlChan(ctx context.Context) { - //批量写入数据库 +func (s *sGameAct) Cache2UpdateChan(ctx context.Context) { + //批量更新数据库 updateCount := 0 for v := range updateChan { v.UpdatedAt = gtime.Now() @@ -475,7 +476,12 @@ func (s *sGameAct) Cache2SqlChan(ctx context.Context) { updateCount++ } g.Log().Debugf(ctx, "act当前更新数据库: %v 条", updateCount) + return +} +// Cache2AddChan 批量添加数据库 +func (s *sGameAct) Cache2AddChan(ctx context.Context) { + //批量写入数据库 var addCount int64 for v := range addChan { addRes, err2 := g.Model(Name).Data(v).Insert()