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

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

Instance Method Summary collapse

Instance Method Details

#rebuild_single_tree!(root_id) ⇒ Object



196
197
198
199
200
201
202
203
204
# File 'lib/redmine/nested_set/issue_nested_set.rb', line 196

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



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

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