From: Carl Baldwin Date: Wed, 7 Oct 2015 19:49:27 +0000 (+0000) Subject: Quick optimization to avoid a query if no ports have fixed ips X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=655a1a214736e91e2f0e6186c9650946883bea41;p=openstack-build%2Fneutron-build.git Quick optimization to avoid a query if no ports have fixed ips I just noticed this trivial optimization while working on address scopes changes. Change-Id: I6f852f47c3d9ae5d0bf7a9950e8829f8bcb63cff --- diff --git a/neutron/db/l3_db.py b/neutron/db/l3_db.py index 92df5abd9..b465b5042 100644 --- a/neutron/db/l3_db.py +++ b/neutron/db/l3_db.py @@ -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']