事务锁代码优化

This commit is contained in:
马梓彭 2026-09-20 10:43:31 +08:00
parent 8efb6a3707
commit f5218fd6d7

View File

@ -239,7 +239,7 @@ public class RefereeController : IDynamicApiController
// 同一裁判的报名请求必须串行化,否则并发报名两场重叠赛事时,
// 两个事务可能都在对方写入前通过撞期校验。锁顺序固定为:裁判 -> 赛事名额。
var referee = await _refereeRepository.AsQueryable()
.With("UPDLOCK, HOLDLOCK")
.With("WITH(UPDLOCK, HOLDLOCK)")
.Where(x => x.AppUserId == userId && !x.DeleteMark)
.FirstAsync();
if (referee == null) throw Oops.Bah("裁判档案不存在,请先完善裁判资料");
@ -299,7 +299,7 @@ public class RefereeController : IDynamicApiController
{
// Apply 由 UnitOfWork 包裹。更新锁和范围锁会把同一赛事的“统计名额并新增报名”串行化,
// 防止最后一个名额被并发请求同时占用。
applicationsQuery = applicationsQuery.With("UPDLOCK, HOLDLOCK");
applicationsQuery = applicationsQuery.With("WITH(UPDLOCK, HOLDLOCK)");
}
var activeApplications = await applicationsQuery