From 4f8f293db3c9d8584a9352323e09c3f912e5f0f8 Mon Sep 17 00:00:00 2001 From: bcmmbaga Date: Fri, 20 Dec 2024 11:43:00 +0300 Subject: [PATCH] Reuse evaluated variables Signed-off-by: bcmmbaga --- management/server/types/account.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/management/server/types/account.go b/management/server/types/account.go index 30ab5a18351..5d0f1201984 100644 --- a/management/server/types/account.go +++ b/management/server/types/account.go @@ -1309,10 +1309,12 @@ func (a *Account) GetNetworkResourcesRoutesToSync(ctx context.Context, peerID st var allSourcePeers []string for _, resource := range a.NetworkResources { + var addSourcePeers bool + networkRoutingPeers, exists := routers[resource.NetworkID] if exists { if router, ok := networkRoutingPeers[peerID]; ok { - isRoutingPeer = true + isRoutingPeer, addSourcePeers = true, true routes = append(routes, a.getNetworkResourcesRoutes(resource, peerID, router, resourcePolicies)...) } } @@ -1326,13 +1328,13 @@ func (a *Account) GetNetworkResourcesRoutesToSync(ctx context.Context, peerID st } // routing peer should be able to connect with all source peers - if _, ok := networkRoutingPeers[peerID]; ok { + if addSourcePeers { allSourcePeers = append(allSourcePeers, group.Peers...) } // add routes for the resource if the peer is in the distribution group if slices.Contains(group.Peers, peerID) { - for peerId, router := range routers[resource.NetworkID] { + for peerId, router := range networkRoutingPeers { routes = append(routes, a.getNetworkResourcesRoutes(resource, peerId, router, resourcePolicies)...) } }