From 01c97c37f7c928f63f112e0d4408511d932daed4 Mon Sep 17 00:00:00 2001 From: liaoyulong Date: Wed, 3 Dec 2025 16:38:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=A8=E9=87=8Aact=E6=8C=81=E4=B9=85?= =?UTF-8?q?=E5=8C=96=E7=9A=84=E5=86=97=E4=BD=99=E6=89=93=E5=8D=B0=20?= =?UTF-8?q?=E6=9C=80=E5=90=8E=E6=89=A7=E8=A1=8C=E7=BB=93=E6=9D=9F=E5=90=8E?= =?UTF-8?q?=E6=89=93=E5=8D=B0=E6=9C=80=E7=BB=88=E8=AE=A1=E6=95=B0?= 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 581b62f..6faef75 100644 --- a/internal/logic/gameAct/gameAct.go +++ b/internal/logic/gameAct/gameAct.go @@ -510,6 +510,8 @@ func (s *sGameAct) Cache2SqlChan(ctx context.Context, addChan, updateChan chan * //通道关闭标志 addClosed := false updateClosed := false + //写入总数 + var addAllCount, updateAllCount int64 tx, err := g.DB().Begin(ctx) if err != nil { @@ -545,12 +547,14 @@ func (s *sGameAct) Cache2SqlChan(ctx context.Context, addChan, updateChan chan * addCount += row if addCount > TaskMax { - g.Log().Debugf(ctx, "超过%v条,act当前写入数据库: %v 条", TaskMax, addCount) + // g.Log().Debugf(ctx, "超过%v条,act当前写入数据库: %v 条", TaskMax, addCount) err = tx.Commit() if err != nil { g.Log().Debugf(ctx, "act当前写入数据库失败:%v", err) return } + //清空数量前累加一下 + addAllCount += addCount addCount = 0 tx, err = g.DB().Begin(ctx) } @@ -579,12 +583,14 @@ func (s *sGameAct) Cache2SqlChan(ctx context.Context, addChan, updateChan chan * updateCount++ if updateCount > TaskMax { - g.Log().Debugf(ctx, "超过%v条,act当前更新数据库: %v 条", TaskMax, updateCount) + // g.Log().Debugf(ctx, "超过%v条,act当前更新数据库: %v 条", TaskMax, updateCount) err = tx.Commit() if err != nil { g.Log().Debugf(ctx, "act当前更新数据库失败:%v", err) return } + //清空数量前累加一下 + updateAllCount += updateCount updateCount = 0 tx, err = g.DB().Begin(ctx) } @@ -600,8 +606,8 @@ func (s *sGameAct) Cache2SqlChan(ctx context.Context, addChan, updateChan chan * err = tx.Commit() // 仅在所有通道处理完毕后打印最终计数(移除中间冗余日志) - g.Log().Debugf(ctx, "运行结束act当前写入数据库: %v 条", addCount) - g.Log().Debugf(ctx, "运行结束act当前更新数据库: %v 条", updateCount) + g.Log().Debugf(ctx, "运行结束act当前写入数据库: %v 条", addAllCount) + g.Log().Debugf(ctx, "运行结束act当前更新数据库: %v 条", updateAllCount) return }