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

memoize cfs activated in project to avoid n+1

ulferts50f612e0327c
diff --git a/app/models/type/attributes.rb b/app/models/type/attributes.rb
index e9e14b85d17..f8383f7d533 100644
--- a/app/models/type/attributes.rb
+++ b/app/models/type/attributes.rb
@@ -211,9 +211,14 @@ module Type::Attributes
##
# Returns whether the custom field is active in the given project.
def custom_field_in_project?(attribute, project)
- project
- .all_work_package_custom_fields.pluck(:id)
- .map { |id| "custom_field_#{id}" }
+ custom_fields_in_project = RequestStore.fetch(:"custom_field_in_project_#{project.id}") do
+ project
+ .all_work_package_custom_fields
+ .pluck(:id)
+ .map { |id| "custom_field_#{id}" }
+ end
+
+ custom_fields_in_project
.include? attribute
end
end