Copilot commented on code in PR #13325:
URL: https://github.com/apache/cloudstack/pull/13325#discussion_r4376733506
##########
server/src/main/java/com/cloud/api/ApiResponseHelper.java:
##########
@@ -3610,6 +3621,9 @@ public VpcResponse createVpcResponse(ResponseView view,
Vpc vpc) {
response.setVpcOfferingName(voff.getName());
response.setVpcOfferingConserveMode(voff.isConserveMode());
}
+ VpcDetailVO publicNetworkRateDetail =
vpcDetailsDao.findDetail(vpc.getId(), ApiConstants.PUBLIC_NETWORK_RATE);
+ Integer publicNetworkRate = publicNetworkRateDetail != null ?
NumberUtils.toInt(publicNetworkRateDetail.getValue(), -1) : null;
+ response.setPublicNetworkRate((publicNetworkRate == null ||
publicNetworkRate <= 0) ? -1 : publicNetworkRate);
Review Comment:
This introduces a per-VPC `findDetail(...)` query when building responses,
which can also become an N+1 pattern when listing VPCs at scale. Consider
exposing the public rate via a join/view (similar to other response fields) or
batch-fetching the `PUBLIC_NETWORK_RATE` details for all VPC ids in the
response.
##########
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:
For non-Full responses, this adds a per-network `findDetail(...)` query,
which can lead to an N+1 pattern when listing many networks. Consider fetching
the `networkrate` value as part of the underlying list query/join (e.g., from a
view/join VO), or batch-loading rate details for the result set to avoid
per-row DB lookups.
--
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]