Skip to content

Commit

Permalink
Fix profiles erroring when the player never played
Browse files Browse the repository at this point in the history
Fixes #21
  • Loading branch information
Simyon264 committed Aug 24, 2024
1 parent 92f2e99 commit f17c4ff
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
23 changes: 22 additions & 1 deletion ReplayBrowser/Helpers/ReplayHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public async Task<CollectedPlayerData> GetPlayerProfile(Guid playerGuid, Authent
});
}

var replayPlayers = await _context.Players
var replayPlayers = await _context.Players
.AsNoTracking()
.Where(p => p.Participant.PlayerGuid == playerGuid)
.Where(p => p.Participant.Replay!.Date != null)
Expand All @@ -121,6 +121,27 @@ public async Task<CollectedPlayerData> GetPlayerProfile(Guid playerGuid, Authent
})
.ToListAsync();

if (replayPlayers.Count == 0)
{
return new CollectedPlayerData()
{
PlayerData = new PlayerData()
{
PlayerGuid = playerGuid,
Username = (await _apiHelper.FetchPlayerDataFromGuid(playerGuid)).Username ??
"Unable to fetch username (API error)"
},
PlayerGuid = playerGuid,
Characters = new List<CharacterData>(),
TotalEstimatedPlaytime = TimeSpan.Zero,
TotalRoundsPlayed = 0,
TotalAntagRoundsPlayed = 0,
LastSeen = DateTime.MinValue,
JobCount = new List<JobCountData>(),
GeneratedAt = DateTime.UtcNow
};
}

var replayPlayerGroup = replayPlayers.GroupBy(rp => rp.ReplayId);

var totalRoundsPlayed = replayPlayerGroup.Count();
Expand Down
12 changes: 0 additions & 12 deletions ReplayBrowser/Pages/Profile.razor
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ else if (IsPrivate)
<h1>Protected data (@Username)</h1>
<p>@(Exception?.Message ?? "No info")</p>
}
else if (FailedToLoad)
{
<h1>Error (@Username)</h1>
<p>Failed to load player data. Exception: @(Exception?.Message ?? "No info")</p>
}
else
{
<MetaDataSpecifer
Expand Down Expand Up @@ -197,12 +192,5 @@ else
Exception = e;
_playerData = new();
}
catch (Exception e)
{
FailedToLoad = true;
Exception = e;
_playerData = new();
Log.Error(e, "Failed to load player data.");
}
}
}

0 comments on commit f17c4ff

Please sign in to comment.