Extract method to simplify

This commit is contained in:
Maikel Linke
2019-06-28 13:45:13 +10:00
parent 3e6e0b73ee
commit bfe41d4cbc

View File

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