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++
|
updateCount++
|
||||||
update = make([]*entity.GameAct, 0)
|
update = make([]*entity.GameAct, 0)
|
||||||
@@ -265,10 +265,10 @@ func (s *sGameAct) Save(ctx context.Context, actId int) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v2 := range add {
|
//for _, v2 := range add {
|
||||||
//删除缓存
|
// //删除缓存
|
||||||
go s.DelCacheKey(ctx, v2.ActId, v2.Uid)
|
// s.DelCacheKey(ctx, v2.ActId, v2.Uid)
|
||||||
}
|
//}
|
||||||
|
|
||||||
//g.Log().Debugf(ctx, "当前 %v 写入数据库: %v 条", actId, count)
|
//g.Log().Debugf(ctx, "当前 %v 写入数据库: %v 条", actId, count)
|
||||||
add = make([]*entity.GameAct, 0)
|
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)
|
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)
|
||||||
@@ -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]
|
add = (add)[:0]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -510,6 +510,8 @@ func (s *sGameAct) Cache2SqlChan(ctx context.Context, addChan, updateChan chan *
|
|||||||
//通道关闭标志
|
//通道关闭标志
|
||||||
addClosed := false
|
addClosed := false
|
||||||
updateClosed := false
|
updateClosed := false
|
||||||
|
//写入总数
|
||||||
|
var addAllCount, updateAllCount int64
|
||||||
|
|
||||||
tx, err := g.DB().Begin(ctx)
|
tx, err := g.DB().Begin(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -545,12 +547,14 @@ 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)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
//清空数量前累加一下
|
||||||
|
addAllCount += addCount
|
||||||
addCount = 0
|
addCount = 0
|
||||||
tx, err = g.DB().Begin(ctx)
|
tx, err = g.DB().Begin(ctx)
|
||||||
}
|
}
|
||||||
@@ -579,12 +583,14 @@ 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
|
||||||
}
|
}
|
||||||
|
//清空数量前累加一下
|
||||||
|
updateAllCount += updateCount
|
||||||
updateCount = 0
|
updateCount = 0
|
||||||
tx, err = g.DB().Begin(ctx)
|
tx, err = g.DB().Begin(ctx)
|
||||||
}
|
}
|
||||||
@@ -600,24 +606,26 @@ 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 条", addAllCount)
|
||||||
g.Log().Debugf(ctx, "act当前更新数据库: %v 条", updateCount)
|
g.Log().Debugf(ctx, "运行结束act当前更新数据库: %v 条", updateAllCount)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除缓存key
|
// 删除缓存key
|
||||||
func (s *sGameAct) DelCacheKey(ctx context.Context, aid int, uid int64) {
|
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 {
|
if getBool, _ := pkg.Cache("redis").
|
||||||
return
|
Contains(ctx, fmt.Sprintf("act:update:%d", uid)); getBool {
|
||||||
}
|
return
|
||||||
|
}
|
||||||
|
|
||||||
cacheKey := fmt.Sprintf("act:%v:%v", aid, uid)
|
cacheKey := fmt.Sprintf("act:%v:%v", aid, uid)
|
||||||
_, err := g.Redis().Del(ctx, cacheKey)
|
_, err := g.Redis().Del(ctx, cacheKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.Log().Error(ctx, err)
|
g.Log().Error(ctx, err)
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 清空GetRedDot缓存
|
// 清空GetRedDot缓存
|
||||||
|
|||||||
Reference in New Issue
Block a user