use request store to mitigate n+1 query

pull/5056/head
Jens Ulferts 8 years ago
parent 8c916f12f3
commit 2c382b9d3d
No known key found for this signature in database
GPG Key ID: 3CAA4B1182CF5308
  1. 2
      app/models/custom_value/user_strategy.rb
  2. 2
      app/models/custom_value/version_strategy.rb

@ -30,9 +30,11 @@
class CustomValue::UserStrategy < CustomValue::FormatStrategy class CustomValue::UserStrategy < CustomValue::FormatStrategy
def typed_value def typed_value
unless value.blank? unless value.blank?
RequestStore.fetch(:"user_custom_value_#{value}") do
User.find_by(id: value) User.find_by(id: value)
end end
end end
end
def validate_type_of_value def validate_type_of_value
unless custom_field.possible_values(custom_value.customized).include?(value) unless custom_field.possible_values(custom_value.customized).include?(value)

@ -30,9 +30,11 @@
class CustomValue::VersionStrategy < CustomValue::FormatStrategy class CustomValue::VersionStrategy < CustomValue::FormatStrategy
def typed_value def typed_value
unless value.blank? unless value.blank?
RequestStore.fetch(:"version_custom_value_#{value}") do
Version.find_by(id: value) Version.find_by(id: value)
end end
end end
end
def validate_type_of_value def validate_type_of_value
unless custom_field.possible_values(custom_value.customized).include?(value) unless custom_field.possible_values(custom_value.customized).include?(value)

Loading…
Cancel
Save