From 25c828007d62c0114a0e3eb4c4c17b93cf7b7481 Mon Sep 17 00:00:00 2001 From: Kevin Benton Date: Thu, 16 Oct 2014 21:27:47 -0700 Subject: [PATCH] Optimize query in _select_dhcp_ips_for_network_ids Only query the DB for relevant columns instead of all of the port columns. Partial-Bug: #1373851 Change-Id: I32cd4a0bc6799ce77cea13188676308e3e641d19 (cherry picked from commit 8d430a7f2e903dda06d8d75d6abcd63423c4c0a1) --- neutron/db/securitygroups_rpc_base.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/neutron/db/securitygroups_rpc_base.py b/neutron/db/securitygroups_rpc_base.py index 1dda6bb46..a72b99491 100644 --- a/neutron/db/securitygroups_rpc_base.py +++ b/neutron/db/securitygroups_rpc_base.py @@ -269,7 +269,8 @@ class SecurityGroupServerRpcMixin(sg_db.SecurityGroupDbMixin): def _select_dhcp_ips_for_network_ids(self, context, network_ids): if not network_ids: return {} - query = context.session.query(models_v2.Port, + query = context.session.query(models_v2.Port.mac_address, + models_v2.Port.network_id, models_v2.IPAllocation.ip_address) query = query.join(models_v2.IPAllocation) query = query.filter(models_v2.Port.network_id.in_(network_ids)) @@ -280,14 +281,13 @@ class SecurityGroupServerRpcMixin(sg_db.SecurityGroupDbMixin): for network_id in network_ids: ips[network_id] = [] - for port, ip in query: + for mac_address, network_id, ip in query: if (netaddr.IPAddress(ip).version == 6 and not netaddr.IPAddress(ip).is_link_local()): - mac_address = port['mac_address'] ip = str(ipv6.get_ipv6_addr_by_EUI64(q_const.IPV6_LLA_PREFIX, mac_address)) - if ip not in ips[port['network_id']]: - ips[port['network_id']].append(ip) + if ip not in ips[network_id]: + ips[network_id].append(ip) return ips -- 2.45.2