From 8eb35e491da37b368c8a48c662c1e455d9fd46d0 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Tue, 18 Dec 2018 17:18:10 +0100 Subject: [PATCH] Don't fetch rows by ids of DISTINCT records There's no point on fetching the same records again by the resulting ids of the previous query (nasty way of removing duplicates), when that query has a DISTINCT. --- app/serializers/api/cached_enterprise_serializer.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/serializers/api/cached_enterprise_serializer.rb b/app/serializers/api/cached_enterprise_serializer.rb index 06b3571c1f..6198e28a6c 100644 --- a/app/serializers/api/cached_enterprise_serializer.rb +++ b/app/serializers/api/cached_enterprise_serializer.rb @@ -85,14 +85,12 @@ module Api def distributed_properties if active product_properties = Spree::Property.currently_sold_by(enterprise) - producer_property_ids = ProducerProperty.currently_sold_by(enterprise).pluck(:property_id) + producer_properties = ProducerProperty.currently_sold_by(enterprise) else product_properties = Spree::Property.ever_sold_by(enterprise) - producer_property_ids = ProducerProperty.ever_sold_by(enterprise).pluck(:property_id) + producer_properties = ProducerProperty.ever_sold_by(enterprise) end - producer_properties = Spree::Property.where(id: producer_property_ids) - (product_properties + producer_properties).uniq do |property_object| property_object.property.presentation end