mirror of
https://github.com/netbirdio/netbird.git
synced 2025-03-05 02:11:13 +01:00
Optimize group change effects on account peers
This commit is contained in:
parent
181e8648a8
commit
36d4c21671
@ -165,12 +165,18 @@ func (am *DefaultAccountManager) SaveGroups(ctx context.Context, accountID, user
|
|||||||
eventsToStore = append(eventsToStore, events...)
|
eventsToStore = append(eventsToStore, events...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateAccountPeers := areGroupChangesAffectPeers(account, newGroups)
|
||||||
|
if updateAccountPeers {
|
||||||
account.Network.IncSerial()
|
account.Network.IncSerial()
|
||||||
|
}
|
||||||
|
|
||||||
if err = am.Store.SaveGroups(account.Id, account.Groups); err != nil {
|
if err = am.Store.SaveGroups(account.Id, account.Groups); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if updateAccountPeers {
|
||||||
am.updateAccountPeers(ctx, account)
|
am.updateAccountPeers(ctx, account)
|
||||||
|
}
|
||||||
|
|
||||||
for _, storeEvent := range eventsToStore {
|
for _, storeEvent := range eventsToStore {
|
||||||
storeEvent()
|
storeEvent()
|
||||||
@ -318,10 +324,9 @@ func (am *DefaultAccountManager) GroupAddPeer(ctx context.Context, accountID, gr
|
|||||||
group.Peers = append(group.Peers, peerID)
|
group.Peers = append(group.Peers, peerID)
|
||||||
}
|
}
|
||||||
|
|
||||||
updateAccountPeers := false
|
updateAccountPeers := areGroupChangesAffectPeers(account, []*nbgroup.Group{group})
|
||||||
if areGroupChangesAffectPeers(account, []string{groupID}) {
|
if updateAccountPeers {
|
||||||
account.Network.IncSerial()
|
account.Network.IncSerial()
|
||||||
updateAccountPeers = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = am.Store.SaveAccount(ctx, account); err != nil {
|
if err = am.Store.SaveAccount(ctx, account); err != nil {
|
||||||
@ -350,10 +355,9 @@ func (am *DefaultAccountManager) GroupDeletePeer(ctx context.Context, accountID,
|
|||||||
return status.Errorf(status.NotFound, "group with ID %s not found", groupID)
|
return status.Errorf(status.NotFound, "group with ID %s not found", groupID)
|
||||||
}
|
}
|
||||||
|
|
||||||
updateAccountPeers := false
|
updateAccountPeers := areGroupChangesAffectPeers(account, []*nbgroup.Group{group})
|
||||||
if areGroupChangesAffectPeers(account, []string{groupID}) {
|
if updateAccountPeers {
|
||||||
account.Network.IncSerial()
|
account.Network.IncSerial()
|
||||||
updateAccountPeers = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, itemID := range group.Peers {
|
for i, itemID := range group.Peers {
|
||||||
@ -372,19 +376,15 @@ func (am *DefaultAccountManager) GroupDeletePeer(ctx context.Context, accountID,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func areGroupChangesAffectPeers(account *Account, groups []string) bool {
|
func areGroupChangesAffectPeers(account *Account, groups []*nbgroup.Group) bool {
|
||||||
for _, groupID := range groups {
|
for _, group := range groups {
|
||||||
if _, exists := account.Groups[groupID]; !exists {
|
if linked, _ := isGroupLinkedToDns(account.NameServerGroups, group.ID); linked {
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if linked, _ := isGroupLinkedToDns(account.NameServerGroups, groupID); linked {
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if linked, _ := isGroupLinkedToPolicy(account.Policies, groupID); linked {
|
if linked, _ := isGroupLinkedToPolicy(account.Policies, group.ID); linked {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if linked, _ := isGroupLinkedToRoute(account.Routes, groupID); linked {
|
if linked, _ := isGroupLinkedToRoute(account.Routes, group.ID); linked {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user