修改更新与写入的持计划日志
This commit is contained in:
@@ -237,7 +237,7 @@ func (s *sGameAct) Save(ctx context.Context, actId int) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//删除缓存
|
//删除缓存
|
||||||
//s.DelCacheKey(ctx, v.ActId, v.Uid)
|
s.DelCacheKey(ctx, v.ActId, v.Uid)
|
||||||
|
|
||||||
updateCount++
|
updateCount++
|
||||||
update = make([]*entity.GameAct, 0)
|
update = make([]*entity.GameAct, 0)
|
||||||
@@ -458,10 +458,10 @@ func (s *sGameAct) Cache2Sql(ctx context.Context, add, update []*entity.GameAct)
|
|||||||
tx, err = g.DB().Begin(ctx)
|
tx, err = g.DB().Begin(ctx)
|
||||||
}
|
}
|
||||||
//删除缓存
|
//删除缓存
|
||||||
//s.DelCacheKey(ctx, v.ActId, v.Uid)
|
s.DelCacheKey(ctx, v.ActId, v.Uid)
|
||||||
}
|
}
|
||||||
//循环结束了,最后写入一波
|
//循环结束了,最后写入一波
|
||||||
g.Log().Debugf(ctx, "act当前更新数据库: %v 条", updateCount)
|
g.Log().Debugf(ctx, "Cache2Sql运行结束,act当前更新数据库: %v 条", updateCount)
|
||||||
update = (update)[:0]
|
update = (update)[:0]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -479,7 +479,7 @@ func (s *sGameAct) Cache2Sql(ctx context.Context, add, update []*entity.GameAct)
|
|||||||
}
|
}
|
||||||
addCount++
|
addCount++
|
||||||
if addCount > TaskMax {
|
if addCount > TaskMax {
|
||||||
g.Log().Debugf(ctx, "act当前写入数据库: %v 条", addCount)
|
g.Log().Debugf(ctx, "超过%v条,act当前写入数据库: %v 条", TaskMax, addCount)
|
||||||
err = tx.Commit()
|
err = tx.Commit()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.Log().Debugf(ctx, "act当前写入数据库失败:%v", err)
|
g.Log().Debugf(ctx, "act当前写入数据库失败:%v", err)
|
||||||
@@ -489,11 +489,11 @@ func (s *sGameAct) Cache2Sql(ctx context.Context, add, update []*entity.GameAct)
|
|||||||
tx, err = g.DB().Begin(ctx)
|
tx, err = g.DB().Begin(ctx)
|
||||||
}
|
}
|
||||||
//删除缓存
|
//删除缓存
|
||||||
//s.DelCacheKey(ctx, v.ActId, v.Uid)
|
s.DelCacheKey(ctx, v.ActId, v.Uid)
|
||||||
}
|
}
|
||||||
|
|
||||||
//循环结束了,最后写入一波
|
//循环结束了,最后写入一波
|
||||||
g.Log().Debugf(ctx, "act当前写入数据库: %v 条", addCount)
|
g.Log().Debugf(ctx, "Cache2Sql运行结束,act当前写入数据库: %v 条", addCount)
|
||||||
add = (add)[:0]
|
add = (add)[:0]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -545,7 +545,7 @@ func (s *sGameAct) Cache2SqlChan(ctx context.Context, addChan, updateChan chan *
|
|||||||
addCount += row
|
addCount += row
|
||||||
|
|
||||||
if addCount > TaskMax {
|
if addCount > TaskMax {
|
||||||
g.Log().Debugf(ctx, "act当前写入数据库: %v 条", addCount)
|
g.Log().Debugf(ctx, "超过%v条,act当前写入数据库: %v 条", TaskMax, addCount)
|
||||||
err = tx.Commit()
|
err = tx.Commit()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.Log().Debugf(ctx, "act当前写入数据库失败:%v", err)
|
g.Log().Debugf(ctx, "act当前写入数据库失败:%v", err)
|
||||||
@@ -556,7 +556,7 @@ func (s *sGameAct) Cache2SqlChan(ctx context.Context, addChan, updateChan chan *
|
|||||||
}
|
}
|
||||||
|
|
||||||
//删除缓存
|
//删除缓存
|
||||||
//s.DelCacheKey(ctx, v.ActId, v.Uid)
|
s.DelCacheKey(ctx, v.ActId, v.Uid)
|
||||||
|
|
||||||
case v, ok := <-updateChan:
|
case v, ok := <-updateChan:
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -579,10 +579,10 @@ func (s *sGameAct) Cache2SqlChan(ctx context.Context, addChan, updateChan chan *
|
|||||||
updateCount++
|
updateCount++
|
||||||
|
|
||||||
if updateCount > TaskMax {
|
if updateCount > TaskMax {
|
||||||
g.Log().Debugf(ctx, "act当前写入数据库: %v 条", addCount)
|
g.Log().Debugf(ctx, "超过%v条,act当前更新数据库: %v 条", TaskMax, updateCount)
|
||||||
err = tx.Commit()
|
err = tx.Commit()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.Log().Debugf(ctx, "act当前写入数据库失败:%v", err)
|
g.Log().Debugf(ctx, "act当前更新数据库失败:%v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
updateCount = 0
|
updateCount = 0
|
||||||
@@ -590,7 +590,7 @@ func (s *sGameAct) Cache2SqlChan(ctx context.Context, addChan, updateChan chan *
|
|||||||
}
|
}
|
||||||
|
|
||||||
//删除缓存
|
//删除缓存
|
||||||
//s.DelCacheKey(ctx, v.ActId, v.Uid)
|
s.DelCacheKey(ctx, v.ActId, v.Uid)
|
||||||
|
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
g.Log().Debug(ctx, "act协程被上下文取消")
|
g.Log().Debug(ctx, "act协程被上下文取消")
|
||||||
@@ -600,8 +600,8 @@ func (s *sGameAct) Cache2SqlChan(ctx context.Context, addChan, updateChan chan *
|
|||||||
|
|
||||||
err = tx.Commit()
|
err = tx.Commit()
|
||||||
// 仅在所有通道处理完毕后打印最终计数(移除中间冗余日志)
|
// 仅在所有通道处理完毕后打印最终计数(移除中间冗余日志)
|
||||||
g.Log().Debugf(ctx, "act当前写入数据库: %v 条", addCount)
|
g.Log().Debugf(ctx, "运行结束act当前写入数据库: %v 条", addCount)
|
||||||
g.Log().Debugf(ctx, "act当前更新数据库: %v 条", updateCount)
|
g.Log().Debugf(ctx, "运行结束act当前更新数据库: %v 条", updateCount)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user