From 1a847c3c30d0dcc347c4c386ef2087f4d15e21bf Mon Sep 17 00:00:00 2001 From: Nikolay Bekirov Date: Wed, 15 Mar 2017 17:30:28 +0200 Subject: [PATCH] Use batch processing methods in Hierarchy Maintenance when looping through database records --- lib/closure_tree/hierarchy_maintenance.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/closure_tree/hierarchy_maintenance.rb b/lib/closure_tree/hierarchy_maintenance.rb index 7579051d..b114ec3a 100644 --- a/lib/closure_tree/hierarchy_maintenance.rb +++ b/lib/closure_tree/hierarchy_maintenance.rb @@ -53,7 +53,7 @@ def _ct_before_destroy _ct.with_advisory_lock do delete_hierarchy_references if _ct.options[:dependent] == :nullify - self.class.find(self.id).children.each { |c| c.rebuild! } + self.class.find(self.id).children.find_each { |c| c.rebuild! } end end true # don't prevent destruction @@ -79,7 +79,7 @@ def rebuild!(called_by_rebuild = false) _ct_reorder_siblings if !called_by_rebuild end - children.each { |c| c.rebuild!(true) } + children.find_each { |c| c.rebuild!(true) } _ct_reorder_children if _ct.order_is_numeric? && children.present? end @@ -110,7 +110,7 @@ module ClassMethods def rebuild! _ct.with_advisory_lock do hierarchy_class.delete_all # not destroy_all -- we just want a simple truncate. - roots.each { |n| n.send(:rebuild!) } # roots just uses the parent_id column, so this is safe. + roots.find_each { |n| n.send(:rebuild!) } # roots just uses the parent_id column, so this is safe. end nil end