From ec581dccb83c627265f1be72ece768d1563ab36f Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Tue, 28 Apr 2020 14:32:51 +0200 Subject: [PATCH] Use class-based caching for queries in EnterpriseInjectionData --- .../enterprise_injection_data.rb | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/open_food_network/enterprise_injection_data.rb b/lib/open_food_network/enterprise_injection_data.rb index 8bc386b2a6..dd6db131af 100644 --- a/lib/open_food_network/enterprise_injection_data.rb +++ b/lib/open_food_network/enterprise_injection_data.rb @@ -10,11 +10,25 @@ module OpenFoodNetwork end def shipping_method_services - @shipping_method_services ||= Spree::ShippingMethod.services + @shipping_method_services ||= begin + CacheService.cached_data_by_class("shipping_method_services", Spree::ShippingMethod) do + # This result relies on a simple join with DistributorShippingMethod. + # Updated DistributorShippingMethod records touch their associated Spree::ShippingMethod. + Spree::ShippingMethod.services + end + end end def supplied_taxons - @supplied_taxons ||= Spree::Taxon.supplied_taxons + @supplied_taxons ||= begin + CacheService.cached_data_by_class("supplied_taxons", Spree::Taxon) do + # This result relies on a join with associated supplied products, through the + # class Classification which maps the relationship. Classification records touch + # their associated Spree::Taxon when updated. A Spree::Product's primary_taxon + # is also touched when changed. + Spree::Taxon.supplied_taxons + end + end end def all_distributed_taxons