Merge "Elminate join for network owner filter"

This commit is contained in:
Jenkins 2017-02-01 13:54:57 +00:00 committed by Gerrit Code Review
commit ea9d837d55
2 changed files with 5 additions and 15 deletions

View File

@ -316,18 +316,8 @@ class DbBasePluginCommon(common_db_mixin.CommonDbMixin):
def _port_filter_hook(context, original_model, conditions):
# Apply the port filter only in non-admin and non-advsvc context
if db_utils.model_query_scope_is_project(context, original_model):
conditions |= (
(context.tenant_id == models_v2.Network.tenant_id) &
(models_v2.Network.id == models_v2.Port.network_id))
conditions |= (models_v2.Port.network_id.in_(
context.session.query(models_v2.Network.id).
filter(context.project_id == models_v2.Network.project_id).
subquery()))
return conditions
@staticmethod
def _port_query_hook(context, original_model, query):
# we need to outerjoin to networks if the model query scope
# is necessary so we can filter based on network id. without
# this the conditions in the filter hook cause the networks
# table to be added to the FROM statement so we get lots of
# duplicated rows that break the COUNT operation
if db_utils.model_query_scope_is_project(context, original_model):
query = query.outerjoin(models_v2.Network)
return query

View File

@ -1365,6 +1365,6 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon,
db_base_plugin_common.DbBasePluginCommon.register_model_query_hook(
models_v2.Port,
"port",
'_port_query_hook',
None,
'_port_filter_hook',
None)