From e5f3aa720f684cd046a0adbcb495c3a0318a9de5 Mon Sep 17 00:00:00 2001 From: Simon <63975668+Simyon264@users.noreply.github.com> Date: Tue, 20 Aug 2024 14:38:37 +0200 Subject: [PATCH] Speed up logging --- ReplayBrowser/Pages/Admin/Logs.razor | 2 +- ReplayBrowser/Services/AccountService.cs | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/ReplayBrowser/Pages/Admin/Logs.razor b/ReplayBrowser/Pages/Admin/Logs.razor index 0e603dd..f77ffec 100644 --- a/ReplayBrowser/Pages/Admin/Logs.razor +++ b/ReplayBrowser/Pages/Admin/Logs.razor @@ -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; diff --git a/ReplayBrowser/Services/AccountService.cs b/ReplayBrowser/Services/AccountService.cs index 90d3fde..a2a92ff 100644 --- a/ReplayBrowser/Services/AccountService.cs +++ b/ReplayBrowser/Services/AccountService.cs @@ -139,15 +139,23 @@ public void Dispose() _timer?.Dispose(); } - public async Task GetAccount(AuthenticationState authstate) + public async Task GetAccount(AuthenticationState authstate, bool includeHistory = false) { var guid = AccountHelper.GetAccountGuid(authstate); using var scope = _scopeFactory.CreateScope(); var context = scope.ServiceProvider.GetRequiredService(); - 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) { @@ -245,7 +253,6 @@ private Account GetSystemAccount() var context = scope.ServiceProvider.GetRequiredService(); return context.Accounts .Include(a => a.Settings) - .Include(a => a.History) .First(a => a.Guid == Guid.Empty); }