]> source.dussan.org Git - redmine.git/commitdiff
Use r13844 workaround for SQLServer only.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 7 Jan 2015 21:11:05 +0000 (21:11 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 7 Jan 2015 21:11:05 +0000 (21:11 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@13845 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/nested_set/issue_nested_set.rb

index 9d525293f0f887f2fc88b7765bbefd52f519fd1f..eadc7116107112df700bfa12b7bf9b8e96867398 100644 (file)
@@ -149,12 +149,17 @@ module Redmine
       end
 
       def lock_nested_set
-        lock = true
         if self.class.connection.adapter_name =~ /sqlserver/i
           lock = "WITH (ROWLOCK HOLDLOCK UPDLOCK)"
+          # Custom lock for SQLServer
+          # This can be problematic if root_id or parent root_id changes
+          # before locking
+          sets_to_lock = [root_id, parent.try(:root_id)].compact.uniq
+          self.class.reorder(:id).where(:root_id => sets_to_lock).lock(lock).ids
+        else
+          sets_to_lock = [id, parent_id].compact
+          self.class.reorder(:id).where("root_id IN (SELECT root_id FROM #{self.class.table_name} WHERE id IN (?))", sets_to_lock).lock.ids
         end
-        sets_to_lock = [root_id, parent.try(:root_id)].compact.uniq
-        self.class.reorder(:id).where(:root_id => sets_to_lock).lock(lock).ids
       end
 
       def nested_set_scope