Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Performance fix: added memoization of `Taxon#cached_self_and_descenda… (#12837)

Damian Legawiec03b74e929fa3
diff --git a/core/app/models/spree/taxon.rb b/core/app/models/spree/taxon.rb
index 6047bf5da3..ada0149b68 100644
--- a/core/app/models/spree/taxon.rb
+++ b/core/app/models/spree/taxon.rb
@@ -17,10 +17,13 @@ module Spree
include Spree::TranslatableResource
include Spree::TranslatableResourceSlug
include Spree::Metadata
+ include Spree::MemoizedData
if defined?(Spree::Webhooks::HasWebhooks)
include Spree::Webhooks::HasWebhooks
end
+ MEMOIZED_METHODS = %w[cached_self_and_descendants_ids].freeze
+
#
# Magic methods
#
@@ -368,7 +371,7 @@ module Spree
end
def cached_self_and_descendants_ids
- Rails.cache.fetch("#{cache_key_with_version}/descendant-ids") do
+ @cached_self_and_descendants_ids ||= Rails.cache.fetch("#{cache_key_with_version}/descendant-ids") do
self_and_descendants.ids
end
end