some fixes on cache creation stuff I think
This commit is contained in:
@@ -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"));
|
||||
|
||||
@@ -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")]
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -175,8 +175,6 @@ public class UserCleanupService : IHostedService
|
||||
}
|
||||
|
||||
dbContext.GroupPairs.Remove(userGroupPair);
|
||||
|
||||
await dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
_logger.LogInformation("User purged: {uid}", user.UID);
|
||||
|
||||
@@ -25,8 +25,14 @@ public class UserPairCacheService : IHostedService
|
||||
_cache.TryRemove(uid, out _);
|
||||
}
|
||||
|
||||
public async Task<Dictionary<string, UserInfo>> GetAllPairs(string uid, MareDbContext dbContext)
|
||||
public async Task<Dictionary<string, UserInfo>> GetAllPairs(string uid, MareDbContext dbContext, bool ignoreCache = false)
|
||||
{
|
||||
if (ignoreCache)
|
||||
{
|
||||
_cache[uid] = await BuildFullCache(dbContext, uid).ConfigureAwait(false);
|
||||
return _cache[uid];
|
||||
}
|
||||
|
||||
await WaitForProcessing(uid).ConfigureAwait(false);
|
||||
|
||||
if (!_cache.ContainsKey(uid))
|
||||
@@ -99,7 +105,7 @@ public class UserPairCacheService : IHostedService
|
||||
{
|
||||
var pairs = await dbContext.GetAllPairsForUser(uid).ToListAsync().ConfigureAwait(false);
|
||||
|
||||
return pairs.GroupBy(g => g.OtherUserUID, StringComparer.Ordinal)
|
||||
var pairsDict = pairs.GroupBy(g => g.OtherUserUID, StringComparer.Ordinal)
|
||||
.ToDictionary(g => g.Key, g =>
|
||||
{
|
||||
return new UserInfo(g.First().Alias,
|
||||
@@ -109,6 +115,8 @@ public class UserPairCacheService : IHostedService
|
||||
g.First().OwnPermissions,
|
||||
g.First().OtherPermissions);
|
||||
}, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
return pairsDict.Where(p => p.Value.OwnPermissions != null).ToDictionary(u => u.Key, u => u.Value, StringComparer.Ordinal);
|
||||
}
|
||||
|
||||
private async Task<UserInfo?> BuildIndividualCache(MareDbContext dbContext, string uid, string otheruid)
|
||||
@@ -118,12 +126,14 @@ public class UserPairCacheService : IHostedService
|
||||
if (!pairs.Any()) return null;
|
||||
|
||||
var groups = pairs.Select(g => g.GID).ToList();
|
||||
return new UserInfo(pairs[0].Alias,
|
||||
var userInfo = new UserInfo(pairs[0].Alias,
|
||||
pairs.SingleOrDefault(p => string.IsNullOrEmpty(p.GID))?.Synced ?? false,
|
||||
pairs.Max(p => p.Synced),
|
||||
pairs.Select(p => string.IsNullOrEmpty(p.GID) ? Constants.IndividualKeyword : p.GID).ToList(),
|
||||
pairs[0].OwnPermissions,
|
||||
pairs[0].OtherPermissions);
|
||||
|
||||
return userInfo.OwnPermissions == null ? null : userInfo;
|
||||
}
|
||||
|
||||
private async Task ProcessStaleEntries()
|
||||
|
||||
@@ -7,25 +7,25 @@ public class UserPermissionQuery
|
||||
public string Alias { get; set; }
|
||||
public string GID { get; set; }
|
||||
public bool Synced { get; set; }
|
||||
public bool OwnpermIsPaused { get; set; }
|
||||
public bool OwnpermSticky { get; set; }
|
||||
public bool OwnpermDisableAnimations { get; set; }
|
||||
public bool OwnpermDisableSounds { get; set; }
|
||||
public bool OwnpermDisableVFX { get; set; }
|
||||
public bool? OwnpermIsPaused { get; set; }
|
||||
public bool? OwnpermSticky { get; set; }
|
||||
public bool? OwnpermDisableAnimations { get; set; }
|
||||
public bool? OwnpermDisableSounds { get; set; }
|
||||
public bool? OwnpermDisableVFX { get; set; }
|
||||
public bool? OtherpermIsPaused { get; set; }
|
||||
public bool? OtherpermDisableAnimations { get; set; }
|
||||
public bool? OtherpermDisableSounds { get; set; }
|
||||
public bool? OtherpermDisableVFX { get; set; }
|
||||
|
||||
public UserPermissionSet OwnPermissions => new UserPermissionSet
|
||||
public UserPermissionSet? OwnPermissions => OwnpermSticky == null ? null : new UserPermissionSet
|
||||
{
|
||||
UserUID = UserUID,
|
||||
OtherUserUID = OtherUserUID,
|
||||
IsPaused = OwnpermIsPaused,
|
||||
DisableAnimations = OwnpermDisableAnimations,
|
||||
DisableSounds = OwnpermDisableSounds,
|
||||
DisableVFX = OwnpermDisableVFX,
|
||||
Sticky = OwnpermSticky
|
||||
IsPaused = OwnpermIsPaused.Value,
|
||||
DisableAnimations = OwnpermDisableAnimations.Value,
|
||||
DisableSounds = OwnpermDisableSounds.Value,
|
||||
DisableVFX = OwnpermDisableVFX.Value,
|
||||
Sticky = OwnpermSticky.Value
|
||||
};
|
||||
|
||||
public UserPermissionSet? OtherPermissions => !Synced ? null : new UserPermissionSet
|
||||
|
||||
@@ -20,8 +20,6 @@ public static class SharedDbFunctions
|
||||
newOwner = potentialNewOwner.GroupUserUID;
|
||||
potentialNewOwner.IsPinned = true;
|
||||
potentialNewOwner.IsModerator = false;
|
||||
|
||||
await context.SaveChangesAsync().ConfigureAwait(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -30,8 +28,6 @@ public static class SharedDbFunctions
|
||||
{
|
||||
context.GroupPairs.RemoveRange(groupPairs);
|
||||
context.Groups.Remove(group);
|
||||
|
||||
await context.SaveChangesAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return (groupHasMigrated, newOwner);
|
||||
@@ -96,8 +92,6 @@ public static class SharedDbFunctions
|
||||
}
|
||||
|
||||
dbContext.GroupPairs.Remove(userGroupPair);
|
||||
|
||||
await dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
var defaultPermissions = await dbContext.UserDefaultPreferredPermissions.Where(u => u.UserUID == user.UID).ToListAsync().ConfigureAwait(false);
|
||||
|
||||
Reference in New Issue
Block a user