]> source.dussan.org Git - redmine.git/commitdiff
#lock_nested_set very slow on mysql with thousands of subtasks (#23318).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 8 Oct 2016 09:15:55 +0000 (09:15 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 8 Oct 2016 09:15:55 +0000 (09:15 +0000)
Patch by Stephane Evr.

git-svn-id: http://svn.redmine.org/redmine/trunk@15891 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/nested_set/issue_nested_set.rb

index afbe6b99516865bd55ae9b8b36b7ca81b4011005..e939f96b63142c2e7391ebdf40b98790b123d80f 100644 (file)
@@ -158,7 +158,10 @@ module Redmine
           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
+          self.class.reorder(:id).
+            joins("INNER JOIN #{self.class.table_name} t2 ON #{self.class.table_name}.root_id = t2.root_id").
+            where("t2.id IN (?)", sets_to_lock).
+            lock.ids
         end
       end