]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Remove double queries in l3 DB get methods
authorKevin Benton <blak111@gmail.com>
Fri, 17 Apr 2015 11:28:58 +0000 (04:28 -0700)
committerKevin Benton <blak111@gmail.com>
Fri, 17 Apr 2015 12:13:52 +0000 (05:13 -0700)
Two frequently called functions were querying the routerport table
and the corresponding ports just to get the port ID. Then they were
calling get_ports again with those port IDs, resulting in two queries
to the port table when there should have only been one.

This eliminates the second call to get_ports since all of the necessary
data hase been retrieved from the port table.

Change-Id: I806e9c380b7de048fe084b2baf4b6f92ab0edf6b
Partial-Bug: #1445412

neutron/db/l3_db.py
neutron/db/l3_dvr_db.py

index bc549937b4ea4a8764655ce2ce3afa5d265e096e..501723308b62bf749cc368b24466192113ab0d61 100644 (file)
@@ -1153,10 +1153,8 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase):
             RouterPort.port_type.in_(device_owners)
         )
 
-        # TODO(markmcclain): This is suboptimal but was left to reduce
-        # changeset size since it is late in cycle
-        ports = [rp.port.id for rp in qry]
-        interfaces = self._core_plugin.get_ports(context, {'id': ports})
+        interfaces = [self._core_plugin._make_port_dict(rp.port, None)
+                      for rp in qry]
         if interfaces:
             self._populate_subnets_for_ports(context, interfaces)
         return interfaces
index 9e94cd23fc58c2e5bf6096fa4a5136dead7dbac1..c8d8356014b5e4b64805705b86dc692ba858bd72 100644 (file)
@@ -359,10 +359,8 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
             l3_db.RouterPort.port_type == DEVICE_OWNER_DVR_SNAT
         )
 
-        # TODO(markmcclain): This is suboptimal but was left to reduce
-        # changeset size since it is late in cycle
-        ports = [rp.port.id for rp in qry]
-        interfaces = self._core_plugin.get_ports(context, {'id': ports})
+        interfaces = [self._core_plugin._make_port_dict(rp.port, None)
+                      for rp in qry]
         LOG.debug("Return the SNAT ports: %s", interfaces)
         if interfaces:
             self._populate_subnets_for_ports(context, interfaces)
@@ -560,16 +558,15 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
 
     def get_snat_interface_ports_for_router(self, context, router_id):
         """Return all existing snat_router_interface ports."""
-        # TODO(markmcclain): This is suboptimal but was left to reduce
-        # changeset size since it is late in cycle
         qry = context.session.query(l3_db.RouterPort)
         qry = qry.filter_by(
             router_id=router_id,
             port_type=DEVICE_OWNER_DVR_SNAT
         )
 
-        ports = [rp.port.id for rp in qry]
-        return self._core_plugin.get_ports(context, {'id': ports})
+        ports = [self._core_plugin._make_port_dict(rp.port, None)
+                 for rp in qry]
+        return ports
 
     def add_csnat_router_interface_port(
             self, context, router, network_id, subnet_id, do_pop=True):