From 2c382b9d3d5a91b6a44f119649b7da588a7bcea1 Mon Sep 17 00:00:00 2001 From: Jens Ulferts Date: Tue, 15 Nov 2016 12:47:09 +0100 Subject: [PATCH] use request store to mitigate n+1 query --- app/models/custom_value/user_strategy.rb | 4 +++- app/models/custom_value/version_strategy.rb | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/custom_value/user_strategy.rb b/app/models/custom_value/user_strategy.rb index 50a337fb83..0e775404ad 100644 --- a/app/models/custom_value/user_strategy.rb +++ b/app/models/custom_value/user_strategy.rb @@ -30,7 +30,9 @@ class CustomValue::UserStrategy < CustomValue::FormatStrategy def typed_value unless value.blank? - User.find_by(id: value) + RequestStore.fetch(:"user_custom_value_#{value}") do + User.find_by(id: value) + end end end diff --git a/app/models/custom_value/version_strategy.rb b/app/models/custom_value/version_strategy.rb index 52bb3cf52d..5f7aa49435 100644 --- a/app/models/custom_value/version_strategy.rb +++ b/app/models/custom_value/version_strategy.rb @@ -30,7 +30,9 @@ class CustomValue::VersionStrategy < CustomValue::FormatStrategy def typed_value unless value.blank? - Version.find_by(id: value) + RequestStore.fetch(:"version_custom_value_#{value}") do + Version.find_by(id: value) + end end end