Feature #24167

Rebuild a single nested set with nested_set plugin

Added by Serghei Zagorinyak 6 months ago. Updated 4 months ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Jean-Philippe Lang% Done:

0%

Category:Core Plugins
Target version:3.4.0
Resolution:Fixed

Description

After updating to Redmine 3.3 we began to encounter broken issue trees quite often. Root and parent ids are ok, but lft and rgt values get messed up somehow. We have ~250k issues so using Issue.rebuild_tree! is a rather expensive task with enormous overhead as 99.99% of nested sets are ok and it is usually one or two that get broken from time to time.

I suppose having a possibility to rebuild only a single nested set would be very useful in such situations. Below is the code I'm using to do so now - just added it to /lib/redmine/nested_set/issue_nested_set.rb

def rebuild_single_tree!(root_id)
  root = Issue.find(root_id)
  if root.blank? || !root.parent_id.blank?
    p "Wrong root specified" 
    return
  end
  transaction do           
    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

Associated revisions

Revision 16111
Added by Jean-Philippe Lang 4 months ago

Adds .rebuild_single_tree! to rebuild a single tree (#24167).

History

#1 Updated by Warren Postma 6 months ago

Wouldn't it be nice if Redmine moved to Git and you could just log an MR instead of pasting code or uploading a .patch? Le Sigh.

#14961

#2 Updated by Toshi MARUYAMA 6 months ago

  • Description updated (diff)

#3 Updated by Toshi MARUYAMA 6 months ago

  • Target version set to 3.4.0

#4 Updated by Jean-Philippe Lang 4 months ago

  • Status changed from New to Closed
  • Assignee set to Jean-Philippe Lang
  • Resolution set to Fixed

Feature added in r16111.

Also available in: Atom PDF