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. 4
      app/models/custom_value/user_strategy.rb
  2. 4
      app/models/custom_value/version_strategy.rb

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

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

Loading…
Cancel
Save