Skip to content

Commit

Permalink
use transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
teraa committed Sep 13, 2024
1 parent 83eea0a commit 887b06b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions BattleTrace/Features/Players/FetchPlayers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ await Parallel.ForEachAsync(
sw.Elapsed
);

await using var tsx = await _ctx.Database.BeginTransactionAsync(cancellationToken);

_ctx.PlayerScans.Add(
new PlayerScan
{
Expand All @@ -141,5 +143,7 @@ await _ctx.BulkCopyAsync(
players,
cancellationToken
);

await tsx.CommitAsync(cancellationToken);
}
}
4 changes: 4 additions & 0 deletions BattleTrace/Features/Servers/FetchServers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public async Task Handle(CancellationToken cancellationToken = default)

var now = _time.GetUtcNow();

await using var tsx = await _ctx.Database.BeginTransactionAsync(cancellationToken);

_ctx.ServerScans.Add(
new Data.Models.ServerScan
{
Expand Down Expand Up @@ -105,5 +107,7 @@ await _ctx.BulkCopyAsync(
entities,
cancellationToken
);

await tsx.CommitAsync(cancellationToken);
}
}

0 comments on commit 887b06b

Please sign in to comment.