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

Include permission query in the mapping query to avoid N+1 queries in the project eager loading wrapper.

Dombi Attilac32a442b969f
diff --git a/lib/api/v3/projects/project_eager_loading_wrapper.rb b/lib/api/v3/projects/project_eager_loading_wrapper.rb
index f9f5379f484..d20b652a126 100644
--- a/lib/api/v3/projects/project_eager_loading_wrapper.rb
+++ b/lib/api/v3/projects/project_eager_loading_wrapper.rb
@@ -65,11 +65,10 @@ module API
def custom_fields_from_projects
ProjectCustomFieldProjectMapping
- .eager_load(:project_custom_field, :project)
+ .eager_load(:project_custom_field)
.merge(ProjectCustomField.visible)
+ .where(project_id: Project.allowed_to(User.current, :view_project_attributes))
.each_with_object(Hash.new { |h, k| h[k] = [] }) do |mapping, acc|
- next unless User.current.allowed_in_project?(:view_project_attributes, mapping.project)
-
acc[mapping.project_id] << mapping.project_custom_field
end
end