mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Use inner join for Spree::Taxon.distributed_taxons
This commit is contained in:
@@ -33,20 +33,18 @@ Spree::Taxon.class_eval do
|
||||
|
||||
# Find all the taxons of distributed products for each enterprise, indexed by enterprise.
|
||||
# Format: {enterprise_id => [taxon_id, ...]}
|
||||
def self.distributed_taxons
|
||||
taxons = {}
|
||||
def self.distributed_taxons(which_taxons=:all)
|
||||
# TODO: Why can't we merge(Spree::Product.with_order_cycles_inner) here?
|
||||
taxons = Spree::Taxon.
|
||||
joins(products: {variants_including_master: {exchanges: :order_cycle}}).
|
||||
merge(Exchange.outgoing).
|
||||
select('spree_taxons.*, exchanges.receiver_id AS enterprise_id')
|
||||
|
||||
Spree::Taxon.
|
||||
joins(:products).
|
||||
merge(Spree::Product.with_order_cycles_outer).
|
||||
where('o_exchanges.incoming = ?', false).
|
||||
select('spree_taxons.*, o_exchanges.receiver_id AS enterprise_id').
|
||||
each do |t|
|
||||
taxons[t.enterprise_id.to_i] ||= Set.new
|
||||
taxons[t.enterprise_id.to_i] << t.id
|
||||
end
|
||||
|
||||
taxons
|
||||
taxons.inject({}) do |ts, t|
|
||||
ts[t.enterprise_id.to_i] ||= Set.new
|
||||
ts[t.enterprise_id.to_i] << t.id
|
||||
ts
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user