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


##########
server/src/main/java/com/cloud/api/ApiResponseHelper.java:
##########
@@ -3591,6 +3602,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;

Review Comment:
   `createVpcResponse` is called once per item by `ListVPCsCmd`, so this new 
`findDetail` adds one VPC-details query for every VPC in a list response. That 
creates an avoidable N+1 query pattern for the common list API; load the 
effective rate through the VPC join/list query or batch the details for all 
returned VPC IDs.



##########
server/src/main/java/com/cloud/network/NetworkServiceImpl.java:
##########
@@ -3604,6 +3604,8 @@ public void 
doInTransactionWithoutResult(TransactionStatus status) {
                                     
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_ASSIGN, 
vm.getAccountId(), vm.getDataCenterId(), vm.getId(), nicIdString, 
networkOfferingId,
                                             null, isDefault, 
VirtualMachine.class.getName(), vm.getUuid(), vm.isDisplay());
                                 }
+                                Integer rate = 
_configMgr.getNetworkOfferingNetworkRate(networkOfferingId, 
network.getDataCenterId());
+                                _networkDetailsDao.addDetail(networkId, 
ApiConstants.NETWORKRATE, String.valueOf(rate), true);

Review Comment:
   Changing a network offering can change the effective rate of every attached 
NIC, but this block only refreshes the `network_details.networkrate` value. The 
NIC loop above never updates `nic.networkRate`, so API responses and other 
consumers of the persisted NIC value keep reporting the old rate until each VM 
is prepared again; the new precedence can also make the correct value differ 
per VM. Recompute and persist the rate for each non-placeholder NIC after 
switching the offering, rather than updating only the network-level detail.



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