Skip to content

Commit

Permalink
Increase performance somewhat on profile loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Simyon264 committed Jun 23, 2024
1 parent 673a4f9 commit 93497d4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
24 changes: 12 additions & 12 deletions ReplayBrowser/Helpers/ReplayHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ public async Task<List<Replay>> GetMostRecentReplays(AuthenticationState state)
return cachedPlayerData;
}

var replays = (await _context.Players
.Where(p => p.PlayerGuid == playerGuid)
.Include(p => p.Replay)
.Include(r => r.Replay.RoundEndPlayers)
.Select(p => p.Replay)
.ToListAsync()
).DistinctBy(p => p.Id);
var replays = await _context.Replays
.AsNoTracking()
.Include(r => r.RoundEndPlayers)
.Where(r => r.RoundEndPlayers != null)
.Where(r => r.RoundEndPlayers!.Any(p => p.PlayerGuid == playerGuid))
.Distinct() // only need one instance of each replay
.ToListAsync();

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

foreach (var replay in replays)
{
if (replay == null)
{
Log.Warning("Replay is null for player with GUID {PlayerGuid}", playerGuid);
if (replay.RoundEndPlayers == null)
continue;
}

if (replay.RoundEndPlayers == null)
if (replay.Date == null)
{
Log.Warning("Replay with ID {ReplayId} has no date", replay.Id);
continue;
}

if (replay.Date > lastSeen) // Update last seen
{
Expand Down
2 changes: 2 additions & 0 deletions ReplayBrowser/Pages/Profile.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@using ReplayBrowser.Data
@using Microsoft.AspNetCore.Components.Web
@using ReplayBrowser.Helpers
@using Serilog
@inject AuthenticationStateProvider AuthenticationStateProvider
@inject ReplayHelper ReplayHelper
@attribute [StreamRendering]
Expand Down Expand Up @@ -176,6 +177,7 @@ else
FailedToLoad = true;
Exception = e;
_playerData = new();
Log.Error(e, "Failed to load player data.");
}
}
}

0 comments on commit 93497d4

Please sign in to comment.