Skip to content

Commit 0a590e5

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Use explicit inner join for networks in port query" into stable/yoga
2 parents 8d30f92 + 508d832 commit 0a590e5

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

neutron/db/db_base_plugin_v2.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,18 @@ def _update_subnetpool_dict(orig_pool, new_pool):
110110
return updated
111111

112112

113+
def _port_query_hook(context, original_model, query):
114+
# Apply the port query only in non-admin and non-advsvc context
115+
if ndb_utils.model_query_scope_is_project(context, original_model):
116+
query = query.join(models_v2.Network,
117+
models_v2.Network.id == models_v2.Port.network_id)
118+
return query
119+
120+
113121
def _port_filter_hook(context, original_model, conditions):
114122
# Apply the port filter only in non-admin and non-advsvc context
115123
if ndb_utils.model_query_scope_is_project(context, original_model):
116124
conditions |= and_(
117-
models_v2.Port.network_id == models_v2.Network.id,
118125
models_v2.Network.project_id == context.project_id)
119126
return conditions
120127

@@ -150,7 +157,7 @@ def __new__(cls, *args, **kwargs):
150157
model_query.register_hook(
151158
models_v2.Port,
152159
"port",
153-
query_hook=None,
160+
query_hook=_port_query_hook,
154161
filter_hook=_port_filter_hook,
155162
result_filters=None)
156163
return super(NeutronDbPluginV2, cls).__new__(cls, *args, **kwargs)

0 commit comments

Comments
 (0)