]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Remove unnecessary 'IN vs ==' sql query branches
authorKevin Benton <blak111@gmail.com>
Sat, 21 Mar 2015 16:10:25 +0000 (09:10 -0700)
committerKevin Benton <blak111@gmail.com>
Sat, 21 Mar 2015 16:39:06 +0000 (09:39 -0700)
Removes some branches in the codebase that switch
queries depending on whether a WHERE match is against
a single criteria or multiple criteria. For multiple
options an 'IN' statement was used and for a single
option an '==' was used.

This is completely unnecessary complexity and brancing
in our codebase because the 'col IN items' statement is
just a nice syntax offered by SQL that gets converted into
'col==item1 OR col==item2 OR col==item3...' statements
under the hood. So in the case of one item, 'WHERE col IN "F"'
is the same as 'WHERE col = "F"'.

Change-Id: I8bee8c49d72958f5ae424f87c9dc98b8abe6f579

neutron/db/l3_agentschedulers_db.py
neutron/db/portbindings_db.py

index c0c2052eace37f3f2f39b160ea3adf407924fd99..04425485082cfcd78722d3ab4114b41a442f9f1a 100644 (file)
@@ -312,12 +312,7 @@ class L3AgentSchedulerDbMixin(l3agentscheduler.L3AgentSchedulerPluginBase,
         query = query.options(orm.contains_eager(
                               RouterL3AgentBinding.l3_agent))
         query = query.join(RouterL3AgentBinding.l3_agent)
-        if len(router_ids) > 1:
-            query = query.filter(
-                RouterL3AgentBinding.router_id.in_(router_ids))
-        else:
-            query = query.filter(
-                RouterL3AgentBinding.router_id == router_ids[0])
+        query = query.filter(RouterL3AgentBinding.router_id.in_(router_ids))
         if admin_state_up is not None:
             query = (query.filter(agents_db.Agent.admin_state_up ==
                                   admin_state_up))
@@ -333,12 +328,8 @@ class L3AgentSchedulerDbMixin(l3agentscheduler.L3AgentSchedulerPluginBase,
         if not router_ids:
             return []
         query = context.session.query(RouterL3AgentBinding)
-        if len(router_ids) > 1:
-            query = query.options(joinedload('l3_agent')).filter(
-                RouterL3AgentBinding.router_id.in_(router_ids))
-        else:
-            query = query.options(joinedload('l3_agent')).filter(
-                RouterL3AgentBinding.router_id == router_ids[0])
+        query = query.options(joinedload('l3_agent')).filter(
+            RouterL3AgentBinding.router_id.in_(router_ids))
         return query.all()
 
     def list_l3_agents_hosting_router(self, context, router_id):
index c8ab65c59da5c2d20c8d29cdc6e291973a7920a6..a8feddcefa9367812ebe1709a2025b19b32b3408 100644 (file)
@@ -49,10 +49,7 @@ class PortBindingMixin(portbindings_base.PortBindingBaseMixin):
         values = filters and filters.get(portbindings.HOST_ID, [])
         if not values:
             return query
-        if len(values) == 1:
-            query = query.filter(PortBindingPort.host == values[0])
-        else:
-            query = query.filter(PortBindingPort.host.in_(values))
+        query = query.filter(PortBindingPort.host.in_(values))
         return query
 
     db_base_plugin_v2.NeutronDbPluginV2.register_model_query_hook(