Moti Asayag has uploaded a new change for review. Change subject: engine: Replace inner loop with map ......................................................................
engine: Replace inner loop with map Instead of iterating over all of the interfaces fetched from the DB, and attempting to match their equivalent as report by vdsm by name (also via iterating over all of the host nics), a map simplify the matching action. Change-Id: I093a5c6d0f77bcd038a3c7894af343d87687608a Signed-off-by: Moti Asayag <masa...@redhat.com> --- M backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/CollectVdsNetworkDataVDSCommand.java 1 file changed, 8 insertions(+), 14 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/72/22872/1 diff --git a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/CollectVdsNetworkDataVDSCommand.java b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/CollectVdsNetworkDataVDSCommand.java index d1031d3..44310bb 100644 --- a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/CollectVdsNetworkDataVDSCommand.java +++ b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/CollectVdsNetworkDataVDSCommand.java @@ -169,25 +169,19 @@ InterfaceDao interfaceDAO = DbFacade.getInstance().getInterfaceDao(); List<VdsNetworkInterface> dbIfaces = interfaceDAO.getAllInterfacesForVds(vds.getId()); List<String> updatedIfaces = new ArrayList<String>(); - List<VdsNetworkInterface> dbIfacesToBatch = new ArrayList<>(); + Map<String, VdsNetworkInterface> hostNicsByNames = Entities.entitiesByName(vds.getInterfaces()); // First we check what interfaces need to update/delete for (VdsNetworkInterface dbIface : dbIfaces) { - boolean found = false; + if (hostNicsByNames.containsKey(dbIface.getName())) { + VdsNetworkInterface vdsIface = hostNicsByNames.get(dbIface.getName()); - for (VdsNetworkInterface vdsIface : vds.getInterfaces()) { - if (dbIface.getName().equals(vdsIface.getName())) { - // we preserve only the ID from the Database - // everything else is what we got from getVdsCapabilities - vdsIface.setId(dbIface.getId()); - dbIfacesToBatch.add(vdsIface); - updatedIfaces.add(vdsIface.getName()); - found = true; - break; - } - } - if (!found) { + // we preserve only the ID from the Database + // everything else is what we got from getVdsCapabilities + vdsIface.setId(dbIface.getId()); + dbIfacesToBatch.add(vdsIface); + updatedIfaces.add(vdsIface.getName()); interfaceDAO.removeInterfaceFromVds(dbIface.getId()); interfaceDAO.removeStatisticsForVds(dbIface.getId()); } -- To view, visit http://gerrit.ovirt.org/22872 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I093a5c6d0f77bcd038a3c7894af343d87687608a Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Moti Asayag <masa...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches