Remove unnecessary 'IN vs ==' sql query branches

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
This commit is contained in:
Kevin Benton 2015-03-21 09:10:25 -07:00
parent a840a20729
commit 0e8f7e1712
2 changed files with 4 additions and 16 deletions

View 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):

View 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(