Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide anyone marked as redacted from leaderboard top display entirely #62

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions ReplayBrowser/Services/LeaderboardService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
private readonly AccountService _accountService;
private readonly IConfiguration _configuration;

private List<Guid> RedactedAccounts;

public LeaderboardService(IMemoryCache cache, Ss14ApiHelper apiHelper, IServiceScopeFactory factory, AccountService accountService, IConfiguration configuration)

Check warning on line 33 in ReplayBrowser/Services/LeaderboardService.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'RedactedAccounts' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 33 in ReplayBrowser/Services/LeaderboardService.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'RedactedAccounts' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
{
_cache = cache;
_apiHelper = apiHelper;
Expand All @@ -43,16 +45,29 @@
return Task.CompletedTask;
}

private void DoWork(object? state)
private async void DoWork(object? state)
{
var sw = new Stopwatch();
sw.Start();
Log.Information("Updating leaderboards...");

// Fetch all the redacted players, cache it
// Yeah this ignores whether someone's an admin and doesn't let them bypass this
// Better for performance though

using (var scope = _scopeFactory.CreateScope()) {
var context = scope.ServiceProvider.GetRequiredService<ReplayDbContext>();
RedactedAccounts = await context.Accounts
.Where(a => a.Settings.RedactInformation)
.Select(a => a.Guid)
.ToListAsync();
}

// Loop through every range option.
foreach (var rangeOption in Enum.GetValues<RangeOption>())
{
var anonymousAuth = new AuthenticationState(new ClaimsPrincipal(new ClaimsIdentity()));
GetLeaderboard(rangeOption, null, [], anonymousAuth, 10, false).Wait();
await GetLeaderboard(rangeOption, null, [], anonymousAuth, 10, false);
}

sw.Stop();
Expand All @@ -77,7 +92,8 @@
servers = _configuration.GetSection("ReplayUrls").Get<StorageUrl[]>()!.Select(x => x.FallBackServerName).ToArray();
}

var context = _scopeFactory.CreateScope().ServiceProvider.GetRequiredService<ReplayDbContext>();
using var scope = _scopeFactory.CreateScope();
var context = scope.ServiceProvider.GetRequiredService<ReplayDbContext>();

Account? accountCaller = null;
if (logAction)
Expand Down Expand Up @@ -419,7 +435,7 @@
Leaderboard data,
Guid targetPlayer,
int limit = 10
)
)
{
var returnValue = new Leaderboard()
{
Expand All @@ -428,7 +444,8 @@
Data = new Dictionary<string, PlayerCount>()
};

var players = data.Data.Values.ToList();
var players = data.Data.Values.Where(p => p.Player?.PlayerGuid is null || p.Player.PlayerGuid == Guid.Empty || !RedactedAccounts.Contains(p.Player?.PlayerGuid ?? Guid.Empty)).ToList();

players.Sort((a, b) => b.Count.CompareTo(a.Count));
for (var i = 0; i < players.Count; i++)
{
Expand Down
Loading