From a8d37d0899093d57bb63ac3a30b30f3d1a45ba9a Mon Sep 17 00:00:00 2001 From: David Cook Date: Thu, 24 Aug 2023 08:48:27 +1000 Subject: [PATCH] Apply suggestions from code review Rails is clever enough to not query the database without ids Co-authored-by: Maikel --- app/services/sets/product_set.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/services/sets/product_set.rb b/app/services/sets/product_set.rb index 06f3ac4f4f..7eb73e3bee 100644 --- a/app/services/sets/product_set.rb +++ b/app/services/sets/product_set.rb @@ -20,10 +20,9 @@ module Sets end def collection_attributes=(attributes) - ids = attributes.each_value.map { |product| product[:id] }.compact - @collection = [] + ids = attributes.values.pluck(:id).compact # Find and load existing products in the order they are provided - @collection = Spree::Product.find(ids) if ids.present? + @collection = Spree::Product.find(ids) @collection_hash = attributes end