diff --git a/app/user_center/model/rank_pvp_model.go b/app/user_center/model/rank_pvp_model.go index 5b0b178..eee5aa4 100644 --- a/app/user_center/model/rank_pvp_model.go +++ b/app/user_center/model/rank_pvp_model.go @@ -78,7 +78,7 @@ func (m *customRankPvpModel) RankListByType(ctx context.Context, rankType, topN } func (m *customRankPvpModel) UpdateRank(ctx context.Context, rankType int32, data []RankPvp) error { - db := m.conn.WithContext(ctx) //.Session(&gorm.Session{DryRun: true}) + db := m.conn.WithContext(ctx) return db.Transaction(func(tx *gorm.DB) error { var err error // delete all by rank_type diff --git a/app/user_center/rpc/internal/logic/rank/rank_job.go b/app/user_center/rpc/internal/logic/rank/rank_job.go index aaf65a1..7a721fa 100644 --- a/app/user_center/rpc/internal/logic/rank/rank_job.go +++ b/app/user_center/rpc/internal/logic/rank/rank_job.go @@ -11,6 +11,7 @@ import ( "live-service/app/user_center/model" "live-service/app/user_center/rpc/internal/svc" "live-service/app/user_center/rpc/pb" + "time" ) var Service *Job @@ -300,6 +301,8 @@ func (j *Job) persistence(rankType int32) { }) } if len(dbModel) > 0 { + // 简单避免死锁 + time.Sleep(1 * time.Second) if err = j.svcCtx.RankPvpModel.UpdateRank(j.ctx, rankType, dbModel); err != nil { logx.Error("更新排行榜错误", err) return