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.

Use 1 SQL query to generate collection cache key rather than 2 (#11517)

Damian Legawiec703f3c761356
diff --git a/api/app/controllers/concerns/spree/api/v2/caching.rb b/api/app/controllers/concerns/spree/api/v2/caching.rb
index cd70e2b39e..efc2afa6d0 100644
--- a/api/app/controllers/concerns/spree/api/v2/caching.rb
+++ b/api/app/controllers/concerns/spree/api/v2/caching.rb
@@ -5,11 +5,15 @@ module Spree
extend ActiveSupport::Concern
def collection_cache_key(collection)
- unscoped_collection = collection.unscope(:includes).unscope(:order)
+ ids_and_timestamps = collection.unscope(:includes).unscope(:order).pluck(:id, :updated_at)
+
+ ids = ids_and_timestamps.map(&:first)
+ max_updated_at = ids_and_timestamps.map(&:last).max
+
cache_key_parts = [
self.class.to_s,
- unscoped_collection.maximum(:updated_at),
- unscoped_collection.ids,
+ max_updated_at,
+ ids,
resource_includes,
sparse_fields,
serializer_params,