summaryrefslogtreecommitdiffstats
path: root/lib/redmine/nested_set
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2016-12-10 08:54:20 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2016-12-10 08:54:20 +0000
commit10b3e3e32394216fd8700635e71fd25ea52dfda1 (patch)
treeb48cfcf164d42cf54e7577429ad73615bb7aaa77 /lib/redmine/nested_set
parent49fcec80b7eb42debb749b7eef27b315c137d19f (diff)
downloadredmine-10b3e3e32394216fd8700635e71fd25ea52dfda1.tar.gz
redmine-10b3e3e32394216fd8700635e71fd25ea52dfda1.zip
#lock_nested_set very slow on mysql with thousands of subtasks (#23318).
Patch by Stephane Evr. git-svn-id: http://svn.redmine.org/redmine/trunk@16053 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/redmine/nested_set')
-rw-r--r--lib/redmine/nested_set/issue_nested_set.rb3
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/redmine/nested_set/issue_nested_set.rb b/lib/redmine/nested_set/issue_nested_set.rb
index afbe6b995..3d1293dc2 100644
--- a/lib/redmine/nested_set/issue_nested_set.rb
+++ b/lib/redmine/nested_set/issue_nested_set.rb
@@ -158,7 +158,8 @@ 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
+ inner_join_statement = self.class.select(:root_id).where(id: sets_to_lock).distinct(:root_id).to_sql
+ self.class.reorder(:id).joins("INNER JOIN (#{inner_join_statement}) as i2 ON #{self.class.table_name}.root_id = i2.root_id").lock.ids
end
end