abh1sar commented on code in PR #9096:
URL: https://github.com/apache/cloudstack/pull/9096#discussion_r1609327509


##########
server/src/main/java/com/cloud/network/NetworkServiceImpl.java:
##########
@@ -2322,41 +2322,52 @@ public Pair<List<? extends Network>, Integer> 
searchForNetworks(ListNetworksCmd
             sb.join("associatedNetworkSearch", associatedNetworkSearch, 
sb.entity().getId(), associatedNetworkSearch.entity().getResourceId(), 
JoinBuilder.JoinType.INNER);
         }
 
-        List<NetworkVO> networksToReturn = new ArrayList<NetworkVO>();
+        Pair<List<NetworkVO>, Integer> networks;
+        Pair<List<NetworkVO>, Integer> networksToReturn = new Pair<>(new 
ArrayList<NetworkVO>(), 0);
 
         if (isSystem == null || !isSystem) {
             if (!permittedAccounts.isEmpty()) {
                 if (Arrays.asList(Network.NetworkFilter.Account, 
Network.NetworkFilter.AccountDomain, 
Network.NetworkFilter.All).contains(networkFilter)) {
                     //get account level networks
-                    
networksToReturn.addAll(listAccountSpecificNetworks(buildNetworkSearchCriteria(sb,
 keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, 
networkOfferingId,
-                            aclType, skipProjectNetworks, restartRequired, 
specifyIpRanges, vpcId, tags, display, vlanId, associatedNetworkId), 
searchFilter, permittedAccounts));
+                    networks = 
listAccountSpecificNetworks(buildNetworkSearchCriteria(sb, keyword, id, 
isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, 
networkOfferingId,
+                            aclType, skipProjectNetworks, restartRequired, 
specifyIpRanges, vpcId, tags, display, vlanId, associatedNetworkId), 
searchFilter, permittedAccounts);
+                    networksToReturn.first().addAll(networks.first());
+                    networksToReturn.second(networksToReturn.second() + 
networks.second());
                 }
                 if (domainId != null && 
Arrays.asList(Network.NetworkFilter.Domain, 
Network.NetworkFilter.AccountDomain, 
Network.NetworkFilter.All).contains(networkFilter)) {
                     //get domain level networks
-                    
networksToReturn.addAll(listDomainLevelNetworks(buildNetworkSearchCriteria(sb, 
keyword, id, isSystem, zoneId, guestIpType, trafficType, physicalNetworkId, 
networkOfferingId,
-                            aclType, true, restartRequired, specifyIpRanges, 
vpcId, tags, display, vlanId, associatedNetworkId), searchFilter, domainId, 
false));
+                    networks = 
listDomainLevelNetworks(buildNetworkSearchCriteria(sb, keyword, id, isSystem, 
zoneId, guestIpType, trafficType, physicalNetworkId, networkOfferingId,
+                            aclType, true, restartRequired, specifyIpRanges, 
vpcId, tags, display, vlanId, associatedNetworkId), searchFilter, domainId, 
false);
+                    networksToReturn.first().addAll(networks.first());
+                    networksToReturn.second(networksToReturn.second() + 
networks.second());
                 }
                 if (Arrays.asList(Network.NetworkFilter.Shared, 
Network.NetworkFilter.All).contains(networkFilter)) {
                     // get shared networks
-                    List<NetworkVO> sharedNetworks = 
listSharedNetworks(buildNetworkSearchCriteria(sb, keyword, id, isSystem, 
zoneId, guestIpType, trafficType, physicalNetworkId, networkOfferingId,
+                    Pair<List<NetworkVO>, Integer> sharedNetworks = 
listSharedNetworks(buildNetworkSearchCriteria(sb, keyword, id, isSystem, 
zoneId, guestIpType, trafficType, physicalNetworkId, networkOfferingId,
                             aclType, true, restartRequired, specifyIpRanges, 
vpcId, tags, display, vlanId, associatedNetworkId), searchFilter, 
permittedAccounts);
-                    addNetworksToReturnIfNotExist(networksToReturn, 
sharedNetworks);
+                    addNetworksToReturnIfNotExist(networksToReturn, 
sharedNetworks.first());

Review Comment:
   The total count of result won't be super accurate now.
   As before we would have gone through all the account specific and domain 
level networks and gotten the union with sharedNetworks. That would have 
returned the exact total networks count.
   
   But now we will be working with at max 20 account and domain level networks 
in the list. So there is no way to apply union with all the shared networks.
   
   For example,
   Domain level netowrks = 100
   Shared networks = 100
   Intersection(Domain, Shared) among all of the domain and shared networks = 50
   
   Before this change :
   Total network count = Domain n/w + shared n/w - intersection = 150
   
   After this change:
   Intersection(Domain, shared) among the first 20 domain and shared networks 
returned by the query = 10
   Total network count = Domain n/w + shared n/w - intersection = 190



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to