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.
This commit is contained in:
Pau Perez
2018-12-18 17:18:10 +01:00
parent 328cda66f5
commit 8eb35e491d

View File

@@ -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