]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Quick optimization to avoid a query if no ports have fixed ips
authorCarl Baldwin <carl.baldwin@hpe.com>
Wed, 7 Oct 2015 19:49:27 +0000 (19:49 +0000)
committerCarl Baldwin <carl@ecbaldwin.net>
Fri, 9 Oct 2015 20:36:17 +0000 (20:36 +0000)
I just noticed this trivial optimization while working on address
scopes changes.

Change-Id: I6f852f47c3d9ae5d0bf7a9950e8829f8bcb63cff

neutron/db/l3_db.py

index 92df5abd959711df96ffb7f32d1a5ff889796de2..b465b5042e43d81adb7149a320e2cca62c3f6c28 100644 (file)
@@ -1191,11 +1191,8 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase):
 
         These ports already have fixed_ips populated.
         """
-        if not ports:
-            return
-
         def each_port_having_fixed_ips():
-            for port in ports:
+            for port in ports or []:
                 fixed_ips = port.get('fixed_ips', [])
                 if not fixed_ips:
                     # Skip ports without IPs, which can occur if a subnet
@@ -1208,6 +1205,9 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase):
 
         network_ids = set(p['network_id']
                           for p in each_port_having_fixed_ips())
+        if not network_ids:
+            return
+
         filters = {'network_id': [id for id in network_ids]}
         fields = ['id', 'cidr', 'gateway_ip',
                   'network_id', 'ipv6_ra_mode', 'subnetpool_id']