Skip to content

Commit

Permalink
Use batch processing methods in Hierarchy Maintenance when looping th…
Browse files Browse the repository at this point in the history
…rough database records
  • Loading branch information
NBekirovAcronis committed Mar 15, 2017
1 parent a697630 commit 1a847c3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/closure_tree/hierarchy_maintenance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1a847c3

Please sign in to comment.