Merge pull request #12780 from dacook/optimise-12714

Optimise subscriptions admin
This commit is contained in:
Gaetan Craig-Riou
2024-08-21 09:50:27 +10:00
committed by GitHub
3 changed files with 9 additions and 2 deletions

View File

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

View File

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

View File

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