Skip to content

Commit

Permalink
Speed up logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Simyon264 committed Aug 20, 2024
1 parent 1bdf4f2 commit e5f3aa7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ReplayBrowser/Pages/Admin/Logs.razor
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ else
}

var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
var account = await AccountService.GetAccount(authState);
var account = await AccountService.GetAccount(authState, true);
if (account == null || !account.IsAdmin)
{
Is1984 = true;
Expand Down
19 changes: 13 additions & 6 deletions ReplayBrowser/Services/AccountService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,23 @@ public void Dispose()
_timer?.Dispose();
}

public async Task<Account?> GetAccount(AuthenticationState authstate)
public async Task<Account?> GetAccount(AuthenticationState authstate, bool includeHistory = false)
{
var guid = AccountHelper.GetAccountGuid(authstate);
using var scope = _scopeFactory.CreateScope();
var context = scope.ServiceProvider.GetRequiredService<ReplayDbContext>();
var account = context.Accounts
.Include(a => a.Settings)
.Include(a => a.History)
.FirstOrDefault(a => a.Guid == guid);
Account? account = null;
if (includeHistory)
{
account = context.Accounts
.Include(a => a.Settings)
.Include(a => a.History)
.FirstOrDefault(a => a.Guid == guid);
} else {
account = context.Accounts
.Include(a => a.Settings)
.FirstOrDefault(a => a.Guid == guid);
}

if (account == null)
{
Expand Down Expand Up @@ -245,7 +253,6 @@ private Account GetSystemAccount()
var context = scope.ServiceProvider.GetRequiredService<ReplayDbContext>();
return context.Accounts
.Include(a => a.Settings)
.Include(a => a.History)
.First(a => a.Guid == Guid.Empty);
}

Expand Down

0 comments on commit e5f3aa7

Please sign in to comment.