]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Optimize query in _select_dhcp_ips_for_network_ids
authorKevin Benton <blak111@gmail.com>
Fri, 17 Oct 2014 04:27:47 +0000 (21:27 -0700)
committerKevin Benton <kevinbenton@buttewifi.com>
Wed, 22 Oct 2014 09:46:54 +0000 (09:46 +0000)
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

index 1dda6bb46982325494e504fe61dc7a072f0b7802..a72b994917cc81894c1ed7b03529995eba9ef6bc 100644 (file)
@@ -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