]> source.dussan.org Git - redmine.git/commitdiff
Use EXISTS instead of IN subquery (#21608).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 21 Jan 2017 09:37:18 +0000 (09:37 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 21 Jan 2017 09:37:18 +0000 (09:37 +0000)
Patch by OndÅ™ej Ezr.

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

app/models/project.rb

index fb2ffc3a6ce856074d14b317a17d0da766b77d1c..a09ef781b70716714a7e81e3a813a5bd56df2dab 100644 (file)
@@ -182,7 +182,7 @@ class Project < ActiveRecord::Base
     base_statement = (perm && perm.read? ? "#{Project.table_name}.status <> #{Project::STATUS_ARCHIVED}" : "#{Project.table_name}.status = #{Project::STATUS_ACTIVE}")
     if !options[:skip_pre_condition] && perm && perm.project_module
       # If the permission belongs to a project module, make sure the module is enabled
-      base_statement << " AND #{Project.table_name}.id IN (SELECT em.project_id FROM #{EnabledModule.table_name} em WHERE em.name='#{perm.project_module}')"
+      base_statement << " AND EXISTS (SELECT 1 AS one FROM #{EnabledModule.table_name} em WHERE em.project_id = #{Project.table_name}.id AND em.name='#{perm.project_module}')"
     end
     if project = options[:project]
       project_statement = project.project_condition(options[:with_subprojects])