Skip to content

Commit 1a847c3

Browse files
Use batch processing methods in Hierarchy Maintenance when looping through database records
1 parent a697630 commit 1a847c3

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/closure_tree/hierarchy_maintenance.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def _ct_before_destroy
5353
_ct.with_advisory_lock do
5454
delete_hierarchy_references
5555
if _ct.options[:dependent] == :nullify
56-
self.class.find(self.id).children.each { |c| c.rebuild! }
56+
self.class.find(self.id).children.find_each { |c| c.rebuild! }
5757
end
5858
end
5959
true # don't prevent destruction
@@ -79,7 +79,7 @@ def rebuild!(called_by_rebuild = false)
7979
_ct_reorder_siblings if !called_by_rebuild
8080
end
8181

82-
children.each { |c| c.rebuild!(true) }
82+
children.find_each { |c| c.rebuild!(true) }
8383

8484
_ct_reorder_children if _ct.order_is_numeric? && children.present?
8585
end
@@ -110,7 +110,7 @@ module ClassMethods
110110
def rebuild!
111111
_ct.with_advisory_lock do
112112
hierarchy_class.delete_all # not destroy_all -- we just want a simple truncate.
113-
roots.each { |n| n.send(:rebuild!) } # roots just uses the parent_id column, so this is safe.
113+
roots.find_each { |n| n.send(:rebuild!) } # roots just uses the parent_id column, so this is safe.
114114
end
115115
nil
116116
end

0 commit comments

Comments
 (0)