From 310a2dcb5c7c86dd7e2fe871c1bd3ff156ab7c95 Mon Sep 17 00:00:00 2001 From: NorthLan <6995syu@163.com> Date: Thu, 5 May 2022 10:32:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9A=82=E6=97=B6=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=AD=BB=E9=94=81=E9=97=AE=E9=A2=98=E3=80=82sleep?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/user_center/model/rank_pvp_model.go | 2 +- app/user_center/rpc/internal/logic/rank/rank_job.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) 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