From a033bf361a5e97cd9cb8a6d3bbdbceed76a3c4ca Mon Sep 17 00:00:00 2001 From: gamer147 Date: Sun, 31 May 2026 18:48:26 -0400 Subject: [PATCH] fix(battle-pass): remove redundant SaveChanges after CommitAsync MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CommitAsync's inner SaveChangesAsync already flushes the AddClaim rows + progress.IsPremium mutation alongside the inventory grants (same scoped DbContext). The trailing _db.SaveChangesAsync was a no-op in BuyPremium and only meaningful in AddPoints when no level crossed (no tx opened) — restructured to an else branch. Co-Authored-By: Claude Opus 4.7 --- .../Services/BattlePassService.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/SVSim.EmulatedEntrypoint/Services/BattlePassService.cs b/SVSim.EmulatedEntrypoint/Services/BattlePassService.cs index d2ad0c3..15df87c 100644 --- a/SVSim.EmulatedEntrypoint/Services/BattlePassService.cs +++ b/SVSim.EmulatedEntrypoint/Services/BattlePassService.cs @@ -191,8 +191,9 @@ public sealed class BattlePassService : IBattlePassService // op, any grants override the post-state. result.RewardList carries the final // post-state including the deducted crystal balance. result.Deltas carries the raw // grant amounts for achieved_info (no spend entry in Deltas, only GrantOps). + // CommitAsync's SaveChangesAsync flushes the AddClaim rows + the progress.IsPremium + // mutation alongside the inventory grants — all tracked on the same scoped DbContext. var result = await tx.CommitAsync(ct); - await _db.SaveChangesAsync(ct); // flush claim rows added via _viewerBp.AddClaim return new BattlePassBuyOutcome(1, result.Deltas, result.RewardList); } @@ -246,8 +247,12 @@ public sealed class BattlePassService : IBattlePassService var result = await tx.CommitAsync(ct); newlyClaimed = result.Deltas; } - - await _db.SaveChangesAsync(ct); + else + { + // No level crossed → no tx opened → still need to persist the progress mutation + // (CurrentPoint/WeeklyPoints/WeeklyPeriodStart) tracked on the scoped DbContext. + await _db.SaveChangesAsync(ct); + } return new BattlePassPointGrant( BeforePoint: beforePoint,