reuse dbcontext where applicable
This commit is contained in:
@@ -81,7 +81,7 @@ public partial class MareHub
|
|||||||
{
|
{
|
||||||
uid ??= UserUID;
|
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)
|
.Where(u => !u.Value.OwnPermissions.IsPaused && u.Value.OtherPermissions != null && !u.Value.OtherPermissions.IsPaused)
|
||||||
.Select(u => u.Key).ToList();
|
.Select(u => u.Key).ToList();
|
||||||
}
|
}
|
||||||
@@ -175,7 +175,7 @@ public partial class MareHub
|
|||||||
private async Task UserGroupLeave(GroupPair groupUserPair, string userIdent, string? uid = null)
|
private async Task UserGroupLeave(GroupPair groupUserPair, string userIdent, string? uid = null)
|
||||||
{
|
{
|
||||||
uid ??= UserUID;
|
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)
|
if (!allUserPairs.TryGetValue(groupUserPair.GroupUserUID, out var info) || !info.IsSynced)
|
||||||
{
|
{
|
||||||
var groupUserIdent = await GetUserIdent(groupUserPair.GroupUserUID).ConfigureAwait(false);
|
var groupUserIdent = await GetUserIdent(groupUserPair.GroupUserUID).ConfigureAwait(false);
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ public partial class MareHub
|
|||||||
groupPreferredPermissions.DisableVFX = dto.GroupPairPermissions.IsDisableVFX();
|
groupPreferredPermissions.DisableVFX = dto.GroupPairPermissions.IsDisableVFX();
|
||||||
|
|
||||||
// set the permissions for every group pair that is not sticky
|
// 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)
|
.Where(u => !u.Value.OwnPermissions.Sticky)
|
||||||
.ToDictionary(d => d.Key, d => d.Value, StringComparer.Ordinal);
|
.ToDictionary(d => d.Key, d => d.Value, StringComparer.Ordinal);
|
||||||
|
|
||||||
@@ -431,7 +431,7 @@ public partial class MareHub
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// get all pairs before we join
|
// 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);
|
.ToDictionary(u => u.Key, u => u.Value, StringComparer.Ordinal);
|
||||||
|
|
||||||
if (oneTimeInvite != null)
|
if (oneTimeInvite != null)
|
||||||
@@ -491,7 +491,7 @@ public partial class MareHub
|
|||||||
_cacheService.MarkAsStale(UserUID, pair.GroupUserUID);
|
_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)
|
foreach (var pair in groupPairs)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ public partial class MareHub
|
|||||||
{
|
{
|
||||||
_logger.LogCallInfo();
|
_logger.LogCallInfo();
|
||||||
|
|
||||||
var pairs = await _cacheService.GetAllPairs(UserUID).ConfigureAwait(false);
|
var pairs = await _cacheService.GetAllPairs(UserUID, _dbContext).ConfigureAwait(false);
|
||||||
return pairs.Select(p =>
|
return pairs.Select(p =>
|
||||||
{
|
{
|
||||||
return new UserFullPairDto(new UserData(p.Key, p.Value.Alias),
|
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)));
|
+ 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();
|
allPairs.Where(p => !p.Value.OwnPermissions.IsPaused && p.Value.OtherPermissions != null && !p.Value.OtherPermissions.IsPaused).ToList();
|
||||||
|
|
||||||
var allPairedUsers = await GetAllPairedUnpausedUsers().ConfigureAwait(false);
|
var allPairedUsers = await GetAllPairedUnpausedUsers().ConfigureAwait(false);
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public class UserPairCacheService : IHostedService
|
|||||||
_cache.TryRemove(uid, out _);
|
_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);
|
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);
|
_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);
|
_cache[uid] = await BuildFullCache(dbContext, uid).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user