sudo87 commented on code in PR #13325:
URL: https://github.com/apache/cloudstack/pull/13325#discussion_r4376858765


##########
server/src/main/java/com/cloud/api/ApiResponseHelper.java:
##########
@@ -2671,14 +2676,20 @@ public NetworkResponse 
createNetworkResponse(ResponseView view, Network network)
             response.setVlan(vlan);
         }
 
-        // return network details only to Root admin
+        int networkRate;
+        // return network details only to Root admin, and take the network 
rate from them to save a lookup
         if (view == ResponseView.Full) {
             Map<String, String> details = new HashMap<>();
             for (NetworkDetailVO detail: 
networkDetailsDao.listDetails(network.getId())) {
                 details.put(detail.getName(),detail.getValue());
             }
             response.setDetails(details);
+            networkRate = 
NumberUtils.toInt(details.get(ApiConstants.NETWORKRATE), -1);
+        } else {
+            NetworkDetailVO networkRateDetail = 
networkDetailsDao.findDetail(network.getId(), ApiConstants.NETWORKRATE);
+            networkRate = networkRateDetail != null ? 
NumberUtils.toInt(networkRateDetail.getValue(), -1) : -1;
         }
+        response.setNetworkRate(networkRate > 0 ? networkRate : -1);

Review Comment:
   Same as the earlier N+1 thread. It’s one indexed lookup per row, and root 
admin already reuses the preloaded details. Batching would mean restructuring 
the list response, so I’m keeping it out of this PR.



-- 
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