Skip to content

Use batch processing methods in Hierarchy Maintenance when looping through database records #258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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