From a8d9ad93365dba06a2c44341fc5082daa363c60c Mon Sep 17 00:00:00 2001 From: Kevin Benton Date: Thu, 29 Jun 2017 15:46:21 -0700 Subject: [PATCH] Use subqueryload in l2pop DB for binding ports This adjusts the l2pop DB queries that leverage the port relationship on the PortBinding and DistributedPortBinding models to ensure that the port gets loaded from the DB as part of the initial query. Without this the number of DB queries will increase with the number of ports since the port wasn't being loaded until the 'port' attribute was referenced on its corresponding binding object. Closes-Bug: #1701288 Change-Id: I7c3b08d525b2c90100c9fe4efaee973cf3a076f3 (cherry picked from commit 5be1ace5462994b492b811e20d8a90caac0fcffd) --- neutron/plugins/ml2/drivers/l2pop/db.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/neutron/plugins/ml2/drivers/l2pop/db.py b/neutron/plugins/ml2/drivers/l2pop/db.py index 80b1a4a2811..548202b1423 100644 --- a/neutron/plugins/ml2/drivers/l2pop/db.py +++ b/neutron/plugins/ml2/drivers/l2pop/db.py @@ -16,6 +16,7 @@ from neutron_lib import constants as const from oslo_serialization import jsonutils from oslo_utils import timeutils +from sqlalchemy import orm from neutron.db import agents_db from neutron.db import l3_hamode_db @@ -70,6 +71,7 @@ def _get_active_network_ports(session, network_id): query = query.join(agents_db.Agent, agents_db.Agent.host == ml2_models.PortBinding.host) query = query.join(models_v2.Port) + query = query.options(orm.subqueryload(ml2_models.PortBinding.port)) query = query.filter(models_v2.Port.network_id == network_id, models_v2.Port.status == const.PORT_STATUS_ACTIVE) return query @@ -109,6 +111,8 @@ def get_dvr_active_network_ports(session, network_id): agents_db.Agent.host == ml2_models.DistributedPortBinding.host) query = query.join(models_v2.Port) + query = query.options( + orm.subqueryload(ml2_models.DistributedPortBinding.port)) query = query.filter(models_v2.Port.network_id == network_id, models_v2.Port.status == const.PORT_STATUS_ACTIVE, models_v2.Port.device_owner ==