]> source.dussan.org Git - redmine.git/commitdiff
Optimizes the SQL query behind Principal#member_of.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 17 Feb 2013 12:41:31 +0000 (12:41 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 17 Feb 2013 12:41:31 +0000 (12:41 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11426 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/principal.rb

index 97babba1ce1fd5056576f0dbc47029b8c4887556..b6f41d535f0a6c031250e64a802f48d0982e7472 100644 (file)
@@ -57,7 +57,7 @@ class Principal < ActiveRecord::Base
       where("1=0")
     else
       ids = projects.map(&:id)
-      active.where("#{Principal.table_name}.id IN (SELECT DISTINCT user_id FROM #{Member.table_name} WHERE project_id IN (?))", ids)
+      active.uniq.joins(:members).where("#{Member.table_name}.project_id IN (?)", ids)
     end
   }
   # Principals that are not members of projects