From bfe41d4cbc5e9a4bfc894ec2dd1e730c27784f04 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 28 Jun 2019 13:45:13 +1000 Subject: [PATCH] Extract method to simplify --- lib/open_food_network/products_cache.rb | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/open_food_network/products_cache.rb b/lib/open_food_network/products_cache.rb index 24fee1ed76..826506c6b8 100644 --- a/lib/open_food_network/products_cache.rb +++ b/lib/open_food_network/products_cache.rb @@ -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).