mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Extract method to simplify
This commit is contained in:
@@ -116,12 +116,7 @@ module OpenFoodNetwork
|
||||
private_class_method :exchanges_featuring_variants
|
||||
|
||||
def self.refresh_incoming_exchanges(exchanges)
|
||||
incoming_exchanges(exchanges).map do |incoming_exchange|
|
||||
outgoing_exchanges_with_variants(
|
||||
incoming_exchange.order_cycle,
|
||||
incoming_exchange.variant_ids
|
||||
)
|
||||
end.flatten.uniq.each do |outgoing_exchange|
|
||||
outgoing_exchanges_affected_by(exchanges).each do |outgoing_exchange|
|
||||
refresh_cache(outgoing_exchange.receiver, outgoing_exchange.order_cycle)
|
||||
end
|
||||
end
|
||||
@@ -169,6 +164,16 @@ module OpenFoodNetwork
|
||||
end
|
||||
private_class_method :incoming_exchanges
|
||||
|
||||
def self.outgoing_exchanges_affected_by(exchanges)
|
||||
incoming_exchanges(exchanges).map do |incoming_exchange|
|
||||
outgoing_exchanges_with_variants(
|
||||
incoming_exchange.order_cycle,
|
||||
incoming_exchange.variant_ids
|
||||
)
|
||||
end.flatten.uniq
|
||||
end
|
||||
private_class_method :outgoing_exchanges_affected_by
|
||||
|
||||
def self.outgoing_exchanges_with_variants(order_cycle, variant_ids)
|
||||
order_cycle.exchanges.outgoing.
|
||||
joins(:exchange_variants).
|
||||
|
||||
Reference in New Issue
Block a user