some fixes on cache creation stuff I think

This commit is contained in:
rootdarkarchon
2023-10-18 09:33:27 +02:00
parent e4a6657391
commit 6fc2f1e90c
7 changed files with 43 additions and 49 deletions

View File

@@ -44,7 +44,6 @@ public partial class MareHub
}
_dbContext.ClientPairs.RemoveRange(ownPairData);
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
var otherPairData = await _dbContext.ClientPairs.Include(u => u.User)
.Where(u => u.OtherUser.UID == user.UID).AsNoTracking().ToListAsync().ConfigureAwait(false);
foreach (var pair in otherPairData)
@@ -64,7 +63,6 @@ public partial class MareHub
_dbContext.GroupPairPreferredPermissions.RemoveRange(groupPermissions);
_dbContext.Permissions.RemoveRange(individualPermissions);
_dbContext.GroupBans.RemoveRange(bannedEntries);
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
_mareMetrics.IncCounter(MetricsAPI.CounterUsersRegisteredDeleted, 1);
@@ -240,7 +238,6 @@ public partial class MareHub
}
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
_cacheService.MarkAsStale(userUid, null);
_logger.LogCallInfo(MareHubLogger.Args(dto, "Success"));

View File

@@ -212,11 +212,6 @@ public partial class MareHub
var notPinned = groupPairs.Where(g => !g.IsPinned && !g.IsModerator).ToList();
_dbContext.GroupPairs.RemoveRange(notPinned);
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
foreach (var user in notPinned)
{
_cacheService.MarkAsStale(user.GroupUserUID, null);
}
foreach (var pair in notPinned)
{
@@ -231,6 +226,12 @@ public partial class MareHub
await UserGroupLeave(groupUserPair, pairIdent, pair.GroupUserUID).ConfigureAwait(false);
}
}
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
foreach (var user in notPinned)
{
_cacheService.MarkAsStale(user.GroupUserUID, null);
}
}
[Authorize(Policy = "Identified")]
@@ -472,7 +473,6 @@ public partial class MareHub
}
await _dbContext.GroupPairs.AddAsync(newPair).ConfigureAwait(false);
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
_logger.LogCallInfo(MareHubLogger.Args(aliasOrGid, "Success"));
@@ -485,13 +485,7 @@ public partial class MareHub
var groupPairs = await _dbContext.GroupPairs.Include(p => p.GroupUser).Where(p => p.GroupGID == group.GID && p.GroupUserUID != UserUID).ToListAsync().ConfigureAwait(false);
_cacheService.MarkAsStale(UserUID, null);
foreach (var pair in groupPairs)
{
_cacheService.MarkAsStale(UserUID, pair.GroupUserUID);
}
var userPairsAfterJoin = await _cacheService.GetAllPairs(UserUID, _dbContext).ConfigureAwait(false);
var userPairsAfterJoin = await _cacheService.GetAllPairs(UserUID, _dbContext, true).ConfigureAwait(false);
foreach (var pair in groupPairs)
{
@@ -581,14 +575,13 @@ public partial class MareHub
}
}
_cacheService.MarkAsStale(UserUID, null);
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
foreach (var pair in groupPairs)
{
_cacheService.MarkAsStale(UserUID, pair.GroupUserUID);
}
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
return true;
}
@@ -613,25 +606,27 @@ public partial class MareHub
_logger.LogCallInfo(MareHubLogger.Args(dto, "Success"));
_dbContext.GroupPairs.Remove(groupPair);
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
_cacheService.MarkAsStale(dto.User.UID, null);
foreach (var user in await _dbContext.GroupPairs.Where(u => u.GroupGID == dto.GID).ToListAsync().ConfigureAwait(false))
{
_cacheService.MarkAsStale(user.GroupUserUID, null);
}
var groupPairs = _dbContext.GroupPairs.Where(p => p.GroupGID == group.GID).AsNoTracking().ToList();
await Clients.Users(groupPairs.Select(p => p.GroupUserUID)).Client_GroupPairLeft(dto).ConfigureAwait(false);
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
var userIdent = await GetUserIdent(dto.User.UID).ConfigureAwait(false);
if (userIdent == null) return;
if (userIdent == null)
{
await _dbContext.SaveChangesAsync().ConfigureAwait(false);
return;
}
await Clients.User(dto.User.UID).Client_GroupDelete(new GroupDto(dto.Group)).ConfigureAwait(false);
foreach (var groupUserPair in groupPairs)
{
await UserGroupLeave(groupUserPair, userIdent, dto.User.UID).ConfigureAwait(false);
_cacheService.MarkAsStale(dto.User.UID, groupUserPair.GroupUserUID);
}
}
[Authorize(Policy = "Identified")]

View File

@@ -171,7 +171,7 @@ public partial class MareHub
{
_logger.LogCallInfo();
var pairs = await _cacheService.GetAllPairs(UserUID, _dbContext).ConfigureAwait(false);
var pairs = await _cacheService.GetAllPairs(UserUID, _dbContext, true).ConfigureAwait(false);
return pairs.Select(p =>
{
return new UserFullPairDto(new UserData(p.Key, p.Value.Alias),