mirror of
https://github.com/netbirdio/netbird.git
synced 2025-03-04 18:01:13 +01:00
Optimize update of account peers on jwt groups sync
This commit is contained in:
parent
1bbd8ae4b0
commit
713c0341be
@ -1723,13 +1723,22 @@ func (am *DefaultAccountManager) GetAccountFromToken(ctx context.Context, claims
|
|||||||
removeOldGroups := difference(oldGroups, user.AutoGroups)
|
removeOldGroups := difference(oldGroups, user.AutoGroups)
|
||||||
account.UserGroupsAddToPeers(claims.UserId, addNewGroups...)
|
account.UserGroupsAddToPeers(claims.UserId, addNewGroups...)
|
||||||
account.UserGroupsRemoveFromPeers(claims.UserId, removeOldGroups...)
|
account.UserGroupsRemoveFromPeers(claims.UserId, removeOldGroups...)
|
||||||
|
|
||||||
|
updateAccountPeers := areGroupChangesAffectPeers(account, addNewGroups) || areGroupChangesAffectPeers(account, removeOldGroups)
|
||||||
|
if updateAccountPeers {
|
||||||
account.Network.IncSerial()
|
account.Network.IncSerial()
|
||||||
|
}
|
||||||
|
|
||||||
if err := am.Store.SaveAccount(ctx, account); err != nil {
|
if err := am.Store.SaveAccount(ctx, account); err != nil {
|
||||||
log.WithContext(ctx).Errorf("failed to save account: %v", err)
|
log.WithContext(ctx).Errorf("failed to save account: %v", err)
|
||||||
} else {
|
} else {
|
||||||
log.WithContext(ctx).Tracef("user %s: JWT group membership changed, updating account peers", claims.UserId)
|
log.WithContext(ctx).Tracef("user %s: JWT group membership changed, updating account peers", claims.UserId)
|
||||||
|
|
||||||
|
if updateAccountPeers {
|
||||||
am.updateAccountPeers(ctx, account)
|
am.updateAccountPeers(ctx, account)
|
||||||
|
}
|
||||||
unlock()
|
unlock()
|
||||||
|
|
||||||
alreadyUnlocked = true
|
alreadyUnlocked = true
|
||||||
for _, g := range addNewGroups {
|
for _, g := range addNewGroups {
|
||||||
if group := account.GetGroup(g); group != nil {
|
if group := account.GetGroup(g); group != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user