mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Merge pull request #5142 from Matt-Yorkley/shops-firefighting
Don't load distributed properties on inactive distributors
This commit is contained in:
@@ -73,12 +73,16 @@ module Api
|
||||
|
||||
# This results in 3 queries per enterprise
|
||||
def distributed_properties
|
||||
return [] unless active
|
||||
|
||||
(distributed_product_properties + distributed_producer_properties).uniq do |property_object|
|
||||
property_object.property.presentation
|
||||
end
|
||||
end
|
||||
|
||||
def distributed_product_properties
|
||||
return [] unless active
|
||||
|
||||
properties = Spree::Property
|
||||
.joins(products: { variants: { exchanges: :order_cycle } })
|
||||
.merge(Exchange.outgoing)
|
||||
@@ -91,6 +95,8 @@ module Api
|
||||
end
|
||||
|
||||
def distributed_producer_properties
|
||||
return [] unless active
|
||||
|
||||
properties = Spree::Property
|
||||
.joins(
|
||||
producer_properties: {
|
||||
|
||||
@@ -60,8 +60,8 @@ feature 'Groups', js: true do
|
||||
let!(:group) { create(:enterprise_group, enterprises: [d1, d2], on_front_page: true) }
|
||||
let!(:order_cycle) { create(:simple_order_cycle, distributors: [d1, d2], coordinator: create(:distributor_enterprise)) }
|
||||
let(:producer) { create(:supplier_enterprise) }
|
||||
let(:d1) { create(:distributor_enterprise) }
|
||||
let(:d2) { create(:distributor_enterprise) }
|
||||
let(:d1) { create(:distributor_enterprise, with_payment_and_shipping: true) }
|
||||
let(:d2) { create(:distributor_enterprise, with_payment_and_shipping: true) }
|
||||
let(:p1) { create(:simple_product, supplier: producer) }
|
||||
let(:p2) { create(:simple_product, supplier: create(:supplier_enterprise)) }
|
||||
let(:ex_d1) { order_cycle.exchanges.outgoing.where(receiver_id: d1).first }
|
||||
|
||||
@@ -53,17 +53,9 @@ describe Api::CachedEnterpriseSerializer do
|
||||
instance_double(OpenFoodNetwork::EnterpriseInjectionData, active_distributor_ids: [])
|
||||
end
|
||||
|
||||
it 'does not duplicate properties' do
|
||||
it 'does not serialize distributed properties' do
|
||||
properties = cached_enterprise_serializer.distributed_properties
|
||||
expect(properties.map(&:presentation)).to eq([property.presentation])
|
||||
end
|
||||
|
||||
it 'fetches producer properties' do
|
||||
distributed_producer_properties = cached_enterprise_serializer
|
||||
.distributed_producer_properties
|
||||
|
||||
expect(distributed_producer_properties.map(&:presentation))
|
||||
.to eq(producer.producer_properties.map(&:property).map(&:presentation))
|
||||
expect(properties).to eq []
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user