Skip to content

Commit

Permalink
memoize cfs activated in project to avoid n+1
Browse files Browse the repository at this point in the history
  • Loading branch information
ulferts authored and oliverguenther committed Oct 24, 2024
1 parent 0f48bb8 commit 50f612e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/models/type/attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 50f612e

Please sign in to comment.