Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Use subselect instead of merging scopes

Oliver Güntherf83d4f0b47a9
diff --git a/lib/api/v3/utilities/endpoints/index.rb b/lib/api/v3/utilities/endpoints/index.rb
index 2333fad71cb..543ab6d53aa 100644
--- a/lib/api/v3/utilities/endpoints/index.rb
+++ b/lib/api/v3/utilities/endpoints/index.rb
@@ -77,7 +77,7 @@ module API
private
def render_success(query, params, self_path, base_scope)
- results = merge_scopes(base_scope, query.results)
+ results = apply_scope_constraint(base_scope, query.results)
if paginated_representer?
render_paginated_success(results, query, params, self_path)
@@ -159,11 +159,11 @@ module API
end
end
- def merge_scopes(scope_a, scope_b)
- if scope_a.is_a? Class
- scope_b
+ def apply_scope_constraint(constraint, result_scope)
+ if constraint.is_a?(Class)
+ result_scope
else
- scope_a.merge(scope_b)
+ result_scope.where id: constraint.select(:id)
end
end
end