diff options
author | Toshi MARUYAMA <marutosijp2@yahoo.co.jp> | 2014-03-26 01:48:20 +0000 |
---|---|---|
committer | Toshi MARUYAMA <marutosijp2@yahoo.co.jp> | 2014-03-26 01:48:20 +0000 |
commit | 2ec3b3694f6b12e28399d25c8c1b96993cb1aa42 (patch) | |
tree | 90cd5751765ccc4da1d1f148b72c9f4870c978af | |
parent | 755108566c0c21760eeae17654ebd37767ed2b9c (diff) | |
download | redmine-2ec3b3694f6b12e28399d25c8c1b96993cb1aa42.tar.gz redmine-2ec3b3694f6b12e28399d25c8c1b96993cb1aa42.zip |
fix race condition of highest rgt at Issue#update_nested_set_attributes_on_parent_change (#6579)
git-svn-id: http://svn.redmine.org/redmine/trunk@13011 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/models/issue.rb | 3 | ||||
-rw-r--r-- | test/unit/issue_nested_set_test.rb | 10 |
2 files changed, 8 insertions, 5 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb index 5a98caa15..8bbb715c4 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -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 diff --git a/test/unit/issue_nested_set_test.rb b/test/unit/issue_nested_set_test.rb index 495d3b785..5b540e588 100644 --- a/test/unit/issue_nested_set_test.rb +++ b/test/unit/issue_nested_set_test.rb @@ -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 |