reuse dbcontext where applicable

This commit is contained in:
rootdarkarchon
2023-10-17 23:18:59 +02:00
parent 0f718dbf43
commit 527b95a271
4 changed files with 8 additions and 9 deletions

View File

@@ -81,7 +81,7 @@ public partial class MareHub
{
uid ??= UserUID;
return (await _cacheService.GetAllPairs(UserUID).ConfigureAwait(false))
return (await _cacheService.GetAllPairs(UserUID, _dbContext).ConfigureAwait(false))
.Where(u => !u.Value.OwnPermissions.IsPaused && u.Value.OtherPermissions != null && !u.Value.OtherPermissions.IsPaused)
.Select(u => u.Key).ToList();
}
@@ -175,7 +175,7 @@ public partial class MareHub
private async Task UserGroupLeave(GroupPair groupUserPair, string userIdent, string? uid = null)
{
uid ??= UserUID;
var allUserPairs = await _cacheService.GetAllPairs(uid).ConfigureAwait(false);
var allUserPairs = await _cacheService.GetAllPairs(uid, _dbContext).ConfigureAwait(false);
if (!allUserPairs.TryGetValue(groupUserPair.GroupUserUID, out var info) || !info.IsSynced)
{
var groupUserIdent = await GetUserIdent(groupUserPair.GroupUserUID).ConfigureAwait(false);

View File

@@ -81,7 +81,7 @@ public partial class MareHub
groupPreferredPermissions.DisableVFX = dto.GroupPairPermissions.IsDisableVFX();
// set the permissions for every group pair that is not sticky
var allPairs = (await _cacheService.GetAllPairs(UserUID).ConfigureAwait(false))
var allPairs = (await _cacheService.GetAllPairs(UserUID, _dbContext).ConfigureAwait(false))
.Where(u => !u.Value.OwnPermissions.Sticky)
.ToDictionary(d => d.Key, d => d.Value, StringComparer.Ordinal);
@@ -431,7 +431,7 @@ public partial class MareHub
return false;
// get all pairs before we join
var allUserPairs = (await _cacheService.GetAllPairs(UserUID).ConfigureAwait(false))
var allUserPairs = (await _cacheService.GetAllPairs(UserUID, _dbContext).ConfigureAwait(false))
.ToDictionary(u => u.Key, u => u.Value, StringComparer.Ordinal);
if (oneTimeInvite != null)
@@ -491,7 +491,7 @@ public partial class MareHub
_cacheService.MarkAsStale(UserUID, pair.GroupUserUID);
}
var userPairsAfterJoin = await _cacheService.GetAllPairs(UserUID).ConfigureAwait(false);
var userPairsAfterJoin = await _cacheService.GetAllPairs(UserUID, _dbContext).ConfigureAwait(false);
foreach (var pair in groupPairs)
{

View File

@@ -171,7 +171,7 @@ public partial class MareHub
{
_logger.LogCallInfo();
var pairs = await _cacheService.GetAllPairs(UserUID).ConfigureAwait(false);
var pairs = await _cacheService.GetAllPairs(UserUID, _dbContext).ConfigureAwait(false);
return pairs.Select(p =>
{
return new UserFullPairDto(new UserData(p.Key, p.Value.Alias),
@@ -263,7 +263,7 @@ public partial class MareHub
+ string.Join(Environment.NewLine, invalidFileSwapPaths.Select(p => "Invalid FileSwap Path: " + p)));
}
var allPairs = await _cacheService.GetAllPairs(UserUID).ConfigureAwait(false);
var allPairs = await _cacheService.GetAllPairs(UserUID, _dbContext).ConfigureAwait(false);
allPairs.Where(p => !p.Value.OwnPermissions.IsPaused && p.Value.OtherPermissions != null && !p.Value.OtherPermissions.IsPaused).ToList();
var allPairedUsers = await GetAllPairedUnpausedUsers().ConfigureAwait(false);

View File

@@ -25,7 +25,7 @@ public class UserPairCacheService : IHostedService
_cache.TryRemove(uid, out _);
}
public async Task<Dictionary<string, UserInfo>> GetAllPairs(string uid)
public async Task<Dictionary<string, UserInfo>> GetAllPairs(string uid, MareDbContext dbContext)
{
await WaitForProcessing(uid).ConfigureAwait(false);
@@ -33,7 +33,6 @@ public class UserPairCacheService : IHostedService
{
_logger.LogDebug("Building full cache: Did not find PairData for {uid}", uid);
using var dbContext = await _dbContextFactory.CreateDbContextAsync().ConfigureAwait(false);
_cache[uid] = await BuildFullCache(dbContext, uid).ConfigureAwait(false);
}