Skip to content

Commit f47548a

Browse files
committed
ReplayImort PlayerIds from ImportServer
1 parent 1db7b22 commit f47548a

File tree

2 files changed

+12
-33
lines changed

2 files changed

+12
-33
lines changed

src/dsstats.db8services/ReplayRepository.cs

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -44,43 +44,17 @@ public async Task SaveReplay(ReplayDto replayDto)
4444

4545
foreach (var replayPlayer in dbReplay.ReplayPlayers)
4646
{
47-
if (replayPlayer.Player.ToonId == 0)
47+
if (replayPlayer.Player!.ToonId == 0)
4848
{
4949
isComputer = true;
5050
}
5151

52-
var dbPlayer = await context.Players.FirstOrDefaultAsync(f =>
53-
f.ToonId == replayPlayer.Player.ToonId
54-
&& f.RealmId == replayPlayer.Player.RealmId
55-
&& f.RegionId == replayPlayer.Player.RegionId);
56-
if (dbPlayer == null)
57-
{
58-
dbPlayer = new()
59-
{
60-
Name = replayPlayer.Player.Name,
61-
ToonId = replayPlayer.Player.ToonId,
62-
RegionId = replayPlayer.Player.RegionId,
63-
RealmId = replayPlayer.Player.RealmId,
64-
};
65-
context.Players.Add(dbPlayer);
66-
try
67-
{
68-
await context.SaveChangesAsync();
69-
}
70-
catch (Exception ex)
71-
{
72-
logger.LogError("failed saving replay: {error}", ex.Message);
73-
throw;
74-
}
75-
}
76-
else
77-
{
78-
dbPlayer.RegionId = replayPlayer.Player.RegionId;
79-
dbPlayer.Name = replayPlayer.Player.Name;
80-
}
81-
82-
replayPlayer.Player = dbPlayer;
83-
replayPlayer.Name = dbPlayer.Name;
52+
replayPlayer.PlayerId = await importService
53+
.GetPlayerIdAsync(new(replayPlayer.Player.ToonId, replayPlayer.Player.RealmId, replayPlayer.Player.RegionId),
54+
replayPlayer.Name);
55+
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
56+
replayPlayer.Player = null;
57+
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
8458

8559
foreach (var spawn in replayPlayer.Spawns)
8660
{
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"sdk": {
3+
"version": "8.0.408"
4+
}
5+
}

0 commit comments

Comments
 (0)