Module: Redmine::NestedSet::IssueNestedSet::ClassMethods

Defined in:
lib/redmine/nested_set/issue_nested_set.rb

Overview

Since:

  • 3.0.0

Instance Method Summary collapse

Instance Method Details

#rebuild_single_tree!(root_id) ⇒ Object

Since:

  • 3.4.0



186
187
188
189
190
191
192
193
194
# File 'lib/redmine/nested_set/issue_nested_set.rb', line 186

def rebuild_single_tree!(root_id)
  root = Issue.where(:parent_id => nil).find(root_id)
  transaction do
    where(root_id: root_id).reorder(:id).lock.ids
    where(root_id: root_id).update_all(:lft => nil, :rgt => nil)
    where(root_id: root_id, parent_id: nil).update_all(["lft = ?, rgt = ?", 1, 2])
    rebuild_nodes(root_id)
  end
end

#rebuild_tree!Object



174
175
176
177
178
179
180
181
182
183
184
# File 'lib/redmine/nested_set/issue_nested_set.rb', line 174

def rebuild_tree!
  transaction do
    reorder(:id).lock.ids
    update_all(:root_id => nil, :lft => nil, :rgt => nil)
    where(:parent_id => nil).update_all(["root_id = id, lft = ?, rgt = ?", 1, 2])
    roots_with_children = joins("JOIN #{table_name} parent ON parent.id = #{table_name}.parent_id AND parent.id = parent.root_id").distinct.pluck("parent.id")
    roots_with_children.each do |root_id|
      rebuild_nodes(root_id)
    end
  end
end