Merge branch 'master' of https://gitea.adesk.com/public_project/utility_go
This commit is contained in:
@@ -237,7 +237,7 @@ func (s *sGameAct) Save(ctx context.Context, actId int) (err error) {
|
||||
}
|
||||
|
||||
//删除缓存
|
||||
go s.DelCacheKey(ctx, v.ActId, v.Uid)
|
||||
s.DelCacheKey(ctx, v.ActId, v.Uid)
|
||||
|
||||
updateCount++
|
||||
update = make([]*entity.GameAct, 0)
|
||||
@@ -265,10 +265,10 @@ func (s *sGameAct) Save(ctx context.Context, actId int) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
for _, v2 := range add {
|
||||
//删除缓存
|
||||
go s.DelCacheKey(ctx, v2.ActId, v2.Uid)
|
||||
}
|
||||
//for _, v2 := range add {
|
||||
// //删除缓存
|
||||
// s.DelCacheKey(ctx, v2.ActId, v2.Uid)
|
||||
//}
|
||||
|
||||
//g.Log().Debugf(ctx, "当前 %v 写入数据库: %v 条", actId, count)
|
||||
add = make([]*entity.GameAct, 0)
|
||||
@@ -461,7 +461,7 @@ func (s *sGameAct) Cache2Sql(ctx context.Context, add, update []*entity.GameAct)
|
||||
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]
|
||||
}
|
||||
|
||||
@@ -479,7 +479,7 @@ func (s *sGameAct) Cache2Sql(ctx context.Context, add, update []*entity.GameAct)
|
||||
}
|
||||
addCount++
|
||||
if addCount > TaskMax {
|
||||
g.Log().Debugf(ctx, "act当前写入数据库: %v 条", addCount)
|
||||
g.Log().Debugf(ctx, "超过%v条,act当前写入数据库: %v 条", TaskMax, addCount)
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
g.Log().Debugf(ctx, "act当前写入数据库失败:%v", err)
|
||||
@@ -493,7 +493,7 @@ func (s *sGameAct) Cache2Sql(ctx context.Context, add, update []*entity.GameAct)
|
||||
}
|
||||
|
||||
//循环结束了,最后写入一波
|
||||
g.Log().Debugf(ctx, "act当前写入数据库: %v 条", addCount)
|
||||
g.Log().Debugf(ctx, "Cache2Sql运行结束,act当前写入数据库: %v 条", addCount)
|
||||
add = (add)[:0]
|
||||
}
|
||||
|
||||
@@ -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, "act当前写入数据库: %v 条", 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, "act当前写入数据库: %v 条", addCount)
|
||||
// g.Log().Debugf(ctx, "超过%v条,act当前更新数据库: %v 条", TaskMax, updateCount)
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
g.Log().Debugf(ctx, "act当前写入数据库失败:%v", err)
|
||||
g.Log().Debugf(ctx, "act当前更新数据库失败:%v", err)
|
||||
return
|
||||
}
|
||||
//清空数量前累加一下
|
||||
updateAllCount += updateCount
|
||||
updateCount = 0
|
||||
tx, err = g.DB().Begin(ctx)
|
||||
}
|
||||
@@ -600,13 +606,14 @@ 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
|
||||
}
|
||||
|
||||
// 删除缓存key
|
||||
func (s *sGameAct) DelCacheKey(ctx context.Context, aid int, uid int64) {
|
||||
go func() {
|
||||
//如果有活跃,跳过删除
|
||||
if getBool, _ := pkg.Cache("redis").
|
||||
Contains(ctx, fmt.Sprintf("act:update:%d", uid)); getBool {
|
||||
@@ -618,6 +625,7 @@ func (s *sGameAct) DelCacheKey(ctx context.Context, aid int, uid int64) {
|
||||
if err != nil {
|
||||
g.Log().Error(ctx, err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// 清空GetRedDot缓存
|
||||
|
||||
Reference in New Issue
Block a user