From 50f612e0327c9f4e5623bb9c6ccd3e57845acd1f Mon Sep 17 00:00:00 2001 From: ulferts Date: Thu, 24 Oct 2024 11:55:36 +0200 Subject: [PATCH] memoize cfs activated in project to avoid n+1 --- app/models/type/attributes.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/models/type/attributes.rb b/app/models/type/attributes.rb index e9e14b85d172..f8383f7d533f 100644 --- a/app/models/type/attributes.rb +++ b/app/models/type/attributes.rb @@ -211,9 +211,14 @@ def active_custom_field_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