diff --git a/engines/order_management/app/services/order_management/subscriptions/variants_list.rb b/engines/order_management/app/services/order_management/subscriptions/variants_list.rb index fb06ed8829..f3a817219a 100644 --- a/engines/order_management/app/services/order_management/subscriptions/variants_list.rb +++ b/engines/order_management/app/services/order_management/subscriptions/variants_list.rb @@ -32,7 +32,9 @@ module OrderManagement .merge(Enterprise.is_primary_producer) .pluck(:parent_id) - other_permitted_producer_ids | [distributor.id] + # Append to the potentially gigantic array instead of using union, which creates a new array + # The db IN statement won't care if there's a duplicate. + other_permitted_producer_ids << distributor.id end def self.outgoing_exchange_variant_ids(distributor) diff --git a/lib/open_food_network/scope_variants_for_search.rb b/lib/open_food_network/scope_variants_for_search.rb index 14a1bc25df..e154096524 100644 --- a/lib/open_food_network/scope_variants_for_search.rb +++ b/lib/open_food_network/scope_variants_for_search.rb @@ -42,7 +42,7 @@ module OpenFoodNetwork end def distributor - Enterprise.find params[:distributor_id] + @distributor ||= Enterprise.find params[:distributor_id] end def scope_to_schedule diff --git a/spec/lib/open_food_network/scope_variants_to_search_spec.rb b/spec/lib/open_food_network/scope_variants_for_search_spec.rb similarity index 98% rename from spec/lib/open_food_network/scope_variants_to_search_spec.rb rename to spec/lib/open_food_network/scope_variants_for_search_spec.rb index c8f6104ae5..fc16580d15 100644 --- a/spec/lib/open_food_network/scope_variants_to_search_spec.rb +++ b/spec/lib/open_food_network/scope_variants_for_search_spec.rb @@ -65,6 +65,11 @@ RSpec.describe OpenFoodNetwork::ScopeVariantsForSearch do let(:params) { { q: "product", distributor_id: d2.id } } it "returns all products distributed through that distributor" do + expect{ result }.to query_database [ + "Enterprise Load", + "VariantOverride Load", + "SQL" + ] expect(result).to include v4 expect(result).not_to include v1, v2, v3 end