Skip to content

Commit 93497d4

Browse files
committed
Increase performance somewhat on profile loading
1 parent 673a4f9 commit 93497d4

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

ReplayBrowser/Helpers/ReplayHelper.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ public async Task<List<Replay>> GetMostRecentReplays(AuthenticationState state)
8282
return cachedPlayerData;
8383
}
8484

85-
var replays = (await _context.Players
86-
.Where(p => p.PlayerGuid == playerGuid)
87-
.Include(p => p.Replay)
88-
.Include(r => r.Replay.RoundEndPlayers)
89-
.Select(p => p.Replay)
90-
.ToListAsync()
91-
).DistinctBy(p => p.Id);
85+
var replays = await _context.Replays
86+
.AsNoTracking()
87+
.Include(r => r.RoundEndPlayers)
88+
.Where(r => r.RoundEndPlayers != null)
89+
.Where(r => r.RoundEndPlayers!.Any(p => p.PlayerGuid == playerGuid))
90+
.Distinct() // only need one instance of each replay
91+
.ToListAsync();
9292

9393
var charactersPlayed = new List<CharacterData>();
9494
var totalPlaytime = TimeSpan.Zero;
@@ -99,14 +99,14 @@ public async Task<List<Replay>> GetMostRecentReplays(AuthenticationState state)
9999

100100
foreach (var replay in replays)
101101
{
102-
if (replay == null)
103-
{
104-
Log.Warning("Replay is null for player with GUID {PlayerGuid}", playerGuid);
102+
if (replay.RoundEndPlayers == null)
105103
continue;
106-
}
107104

108-
if (replay.RoundEndPlayers == null)
105+
if (replay.Date == null)
106+
{
107+
Log.Warning("Replay with ID {ReplayId} has no date", replay.Id);
109108
continue;
109+
}
110110

111111
if (replay.Date > lastSeen) // Update last seen
112112
{

ReplayBrowser/Pages/Profile.razor

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
@using ReplayBrowser.Data
55
@using Microsoft.AspNetCore.Components.Web
66
@using ReplayBrowser.Helpers
7+
@using Serilog
78
@inject AuthenticationStateProvider AuthenticationStateProvider
89
@inject ReplayHelper ReplayHelper
910
@attribute [StreamRendering]
@@ -176,6 +177,7 @@ else
176177
FailedToLoad = true;
177178
Exception = e;
178179
_playerData = new();
180+
Log.Error(e, "Failed to load player data.");
179181
}
180182
}
181183
}

0 commit comments

Comments
 (0)