]> source.dussan.org Git - redmine.git/commitdiff
fix race condition of highest rgt at Issue#update_nested_set_attributes_on_parent_cha...
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Wed, 26 Mar 2014 01:48:20 +0000 (01:48 +0000)
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Wed, 26 Mar 2014 01:48:20 +0000 (01:48 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@13011 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/issue.rb
test/unit/issue_nested_set_test.rb

index 5a98caa158ec4103383382c8eda387ff2769f1a4..8bbb715c408e36c86475a489f9275dc20a200539 100644 (file)
@@ -1316,8 +1316,7 @@ class Issue < ActiveRecord::Base
         self.root_id = (@parent_issue.nil? ? id : @parent_issue.root_id)
         cond = ["root_id = ? AND lft >= ? AND rgt <= ? ", old_root_id, lft, rgt]
         self.class.base_class.select('id').lock(true).where(cond)
-        target_maxright = nested_set_scope.maximum(right_column_name) || 0
-        offset = target_maxright + 1 - lft
+        offset = right_most_bound + 1 - lft
         Issue.where(cond).
           update_all(["root_id = ?, lft = lft + ?, rgt = rgt + ?", root_id, offset, offset])
         self[left_column_name]  = lft + offset
index 495d3b785f450844b3c5a4e025ad2cfaca9ebe7c..5b540e58847c1e5eb2bbf553439b6fe2f10887b4 100644 (file)
@@ -86,6 +86,7 @@ class IssueNestedSetTest < ActiveSupport::TestCase
     parent1 = Issue.generate!
     lft2 = new_issue_lft
     parent2 = Issue.generate!
+    lft3 = new_issue_lft
     child = parent1.generate_child!
     child.parent_issue_id = nil
     child.save!
@@ -94,7 +95,7 @@ class IssueNestedSetTest < ActiveSupport::TestCase
     parent2.reload
     assert_equal [parent1.id, lft1, lft1 + 1], [parent1.root_id, parent1.lft, parent1.rgt]
     assert_equal [parent2.id, lft2, lft2 + 1], [parent2.root_id, parent2.lft, parent2.rgt]
-    assert_equal [child.id, 1, 2], [child.root_id, child.lft, child.rgt]
+    assert_equal [child.id,   lft3, lft3 + 1], [child.root_id, child.lft, child.rgt]
   end
 
   def test_move_a_child_to_another_issue
@@ -145,6 +146,7 @@ class IssueNestedSetTest < ActiveSupport::TestCase
     parent1 = Issue.generate!
     child = parent1.generate_child!
     grandchild = child.generate_child!
+    lft4 = new_issue_lft
     child.reload
     child.project = Project.find(2)
     assert child.save
@@ -152,8 +154,10 @@ class IssueNestedSetTest < ActiveSupport::TestCase
     grandchild.reload
     parent1.reload
     assert_equal [1, parent1.id, lft1, lft1 + 1], [parent1.project_id, parent1.root_id, parent1.lft, parent1.rgt]
-    assert_equal [2, child.id, 1, 4], [child.project_id, child.root_id, child.lft, child.rgt]
-    assert_equal [2, child.id, 2, 3], [grandchild.project_id, grandchild.root_id, grandchild.lft, grandchild.rgt]
+    assert_equal [2, child.id, lft4, lft4 + 3],
+                 [child.project_id, child.root_id, child.lft, child.rgt]
+    assert_equal [2, child.id, lft4 + 1, lft4 + 2],
+                 [grandchild.project_id, grandchild.root_id, grandchild.lft, grandchild.rgt]
   end
 
   def test_moving_an_issue_to_a_descendant_should_not_validate