Skip to content

Commit

Permalink
Remove redaction from leaderboards and add per job leaderboards
Browse files Browse the repository at this point in the history
  • Loading branch information
Simyon264 committed May 18, 2024
1 parent aa39270 commit b0ee3dd
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions ReplayBrowser/Services/LeaderboardService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public async Task<LeaderboardData> GetLeaderboard(RangeOption rangeOption, strin
.Replace(" ", "-")
.Replace(".", "-")
.Replace("_", "-");
var cacheKey = "leaderboard-" + rangeOption + "-" + usernameCacheKey + "-" + accountCaller?.Guid;
var cacheKey = "leaderboard-" + rangeOption + "-" + usernameCacheKey;
if (_cache.TryGetValue(cacheKey, out LeaderboardData leaderboardData))
{
return leaderboardData;
Expand Down Expand Up @@ -370,6 +370,31 @@ public async Task<LeaderboardData> GetLeaderboard(RangeOption rangeOption, strin
// Delete "Unknown" from the MostPlayedJobs leaderboard
leaderboards["MostPlayedJobs"].Data.Remove("Unknown");

// For every job in MostPlayedJobs, construct a top 10 for that job.
foreach (var (job, _) in leaderboards["MostPlayedJobs"].Data)
{
var jobLeaderboard = new Leaderboard()
{
Name = job,
TrackedData = "Times played",
Data = new Dictionary<string, PlayerCount>()
};
leaderboards.Add(job, jobLeaderboard);

foreach (var dataReplay in dataReplays)
{
foreach (var dataReplayRoundEndPlayer in dataReplay.RoundEndPlayers)
{
if (dataReplayRoundEndPlayer.JobPrototypes.Contains(job))
{
CountUp(dataReplayRoundEndPlayer, job, ref leaderboards);
}
}
}
}



// Need to calculate the position of every player in the leaderboard.
foreach (var leaderboard in leaderboards)
{
Expand All @@ -379,29 +404,6 @@ public async Task<LeaderboardData> GetLeaderboard(RangeOption rangeOption, strin

stopwatch.Stop();
Log.Information("Calculating leaderboard took {Time}ms", stopwatch.ElapsedMilliseconds);

stopwatch.Restart();

// Redact usernames for redacted players
foreach (var leaderboard in leaderboards)
{
foreach (var player in leaderboard.Value.Data)
{
if (player.Value.Player?.PlayerGuid == null)
continue;
var guid = (Guid)player.Value.Player.PlayerGuid;
var account = _accountService.GetAccountSettings(guid);

if (account == null)
continue;

if (account.RedactInformation && (accountCaller == null || accountCaller.Guid != guid))
{
player.Value.Player.RedactInformation();
}
}
}
Log.Information("Redacting usernames took {Time}ms", stopwatch.ElapsedMilliseconds);

// Save leaderboard to cache (its expensive as fuck to calculate)
var cacheEntryOptions = new MemoryCacheEntryOptions()
Expand Down

0 comments on commit b0ee3dd

Please sign in to comment.