mirror of
https://github.com/netbirdio/netbird.git
synced 2025-03-05 18:31:16 +01:00
Optimize account peers update in DNS settings
This commit is contained in:
parent
a723c424f0
commit
1bbd8ae4b0
@ -89,26 +89,33 @@ func (am *DefaultAccountManager) SaveDNSSettings(ctx context.Context, accountID
|
|||||||
oldSettings := account.DNSSettings.Copy()
|
oldSettings := account.DNSSettings.Copy()
|
||||||
account.DNSSettings = dnsSettingsToSave.Copy()
|
account.DNSSettings = dnsSettingsToSave.Copy()
|
||||||
|
|
||||||
|
addedGroups := difference(dnsSettingsToSave.DisabledManagementGroups, oldSettings.DisabledManagementGroups)
|
||||||
|
removedGroups := difference(oldSettings.DisabledManagementGroups, dnsSettingsToSave.DisabledManagementGroups)
|
||||||
|
|
||||||
|
updateAccountPeers := (areGroupChangesAffectPeers(account, addedGroups) && anyGroupHasPeers(account, addedGroups)) ||
|
||||||
|
areGroupChangesAffectPeers(account, removedGroups) && anyGroupHasPeers(account, removedGroups)
|
||||||
|
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 {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
addedGroups := difference(dnsSettingsToSave.DisabledManagementGroups, oldSettings.DisabledManagementGroups)
|
|
||||||
for _, id := range addedGroups {
|
for _, id := range addedGroups {
|
||||||
group := account.GetGroup(id)
|
group := account.GetGroup(id)
|
||||||
meta := map[string]any{"group": group.Name, "group_id": group.ID}
|
meta := map[string]any{"group": group.Name, "group_id": group.ID}
|
||||||
am.StoreEvent(ctx, userID, accountID, accountID, activity.GroupAddedToDisabledManagementGroups, meta)
|
am.StoreEvent(ctx, userID, accountID, accountID, activity.GroupAddedToDisabledManagementGroups, meta)
|
||||||
}
|
}
|
||||||
|
|
||||||
removedGroups := difference(oldSettings.DisabledManagementGroups, dnsSettingsToSave.DisabledManagementGroups)
|
|
||||||
for _, id := range removedGroups {
|
for _, id := range removedGroups {
|
||||||
group := account.GetGroup(id)
|
group := account.GetGroup(id)
|
||||||
meta := map[string]any{"group": group.Name, "group_id": group.ID}
|
meta := map[string]any{"group": group.Name, "group_id": group.ID}
|
||||||
am.StoreEvent(ctx, userID, accountID, accountID, activity.GroupRemovedFromDisabledManagementGroups, meta)
|
am.StoreEvent(ctx, userID, accountID, accountID, activity.GroupRemovedFromDisabledManagementGroups, meta)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if updateAccountPeers {
|
||||||
am.updateAccountPeers(ctx, account)
|
am.updateAccountPeers(ctx, account)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user