From c4d2b8ca6cf72d93704f62c0ddf649a42bc0863c Mon Sep 17 00:00:00 2001 From: Kevin Benton Date: Fri, 17 Apr 2015 04:28:58 -0700 Subject: [PATCH] Remove double queries in l3 DB get methods 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 (cherry picked from commit 3310c3c3d4c05c0d13f32f08f978ba4813e2a39a) --- neutron/db/l3_db.py | 6 ++---- neutron/db/l3_dvr_db.py | 13 +++++-------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/neutron/db/l3_db.py b/neutron/db/l3_db.py index bc549937b..501723308 100644 --- a/neutron/db/l3_db.py +++ b/neutron/db/l3_db.py @@ -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 diff --git a/neutron/db/l3_dvr_db.py b/neutron/db/l3_dvr_db.py index 9e94cd23f..c8d835601 100644 --- a/neutron/db/l3_dvr_db.py +++ b/neutron/db/l3_dvr_db.py @@ -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): -- 2.45.2