Fix perf with cache
This commit is contained in:
@@ -199,10 +199,11 @@ public class AccountService : IAccountService
|
||||
|
||||
private async Task<IEnumerable<Account>> GetAccountsAsync(User user, bool hideSecrets, bool getBalance)
|
||||
{
|
||||
var result = await _accountRepository.GetAccountsAsync();
|
||||
// Use the new efficient repository method that queries accounts by user directly
|
||||
var result = await _accountRepository.GetAccountsByUserAsync(user);
|
||||
var accounts = new List<Account>();
|
||||
|
||||
foreach (var account in result.Where(a => a.User.Name == user.Name))
|
||||
foreach (var account in result)
|
||||
{
|
||||
await ManagePropertiesAsync(hideSecrets, getBalance, account);
|
||||
accounts.Add(account);
|
||||
|
||||
@@ -144,12 +144,8 @@ public class UserService : IUserService
|
||||
|
||||
// Fetch from database (either cache miss or cache disabled)
|
||||
var account = await _accountService.GetAccountByKey(address, true, false);
|
||||
var user = await _userRepository.GetUserByNameAsync(account.User.Name);
|
||||
var user = await _userRepository.GetUserByNameAsync(account.User.Name, true);
|
||||
|
||||
// Use proper async version to avoid DbContext concurrency issues
|
||||
user.Accounts = (await _accountService.GetAccountsByUserAsync(user)).ToList();
|
||||
|
||||
// Save to cache for 5 minutes if caching is enabled (JWT middleware calls this on every request)
|
||||
if (useCache)
|
||||
{
|
||||
_cacheService.SaveValue(cacheKey, user, TimeSpan.FromMinutes(5));
|
||||
|
||||
Reference in New Issue
Block a user