Optimize update of account peers on jwt groups sync

This commit is contained in:
bcmmbaga 2024-07-19 14:09:33 +03:00
parent 1bbd8ae4b0
commit 713c0341be
No known key found for this signature in database
GPG Key ID: 7249A19D20613553

View File

@ -1723,13 +1723,22 @@ func (am *DefaultAccountManager) GetAccountFromToken(ctx context.Context, claims
removeOldGroups := difference(oldGroups, user.AutoGroups)
account.UserGroupsAddToPeers(claims.UserId, addNewGroups...)
account.UserGroupsRemoveFromPeers(claims.UserId, removeOldGroups...)
account.Network.IncSerial()
updateAccountPeers := areGroupChangesAffectPeers(account, addNewGroups) || areGroupChangesAffectPeers(account, removeOldGroups)
if updateAccountPeers {
account.Network.IncSerial()
}
if err := am.Store.SaveAccount(ctx, account); err != nil {
log.WithContext(ctx).Errorf("failed to save account: %v", err)
} else {
log.WithContext(ctx).Tracef("user %s: JWT group membership changed, updating account peers", claims.UserId)
am.updateAccountPeers(ctx, account)
if updateAccountPeers {
am.updateAccountPeers(ctx, account)
}
unlock()
alreadyUnlocked = true
for _, g := range addNewGroups {
if group := account.GetGroup(g); group != nil {