From: Jean-Philippe Lang Date: Sun, 17 Feb 2013 12:41:31 +0000 (+0000) Subject: Optimizes the SQL query behind Principal#member_of. X-Git-Tag: 2.3.0~91 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=64bbf64fb6f3b9e89f3180df28c5f06f54638eb8;p=redmine.git Optimizes the SQL query behind Principal#member_of. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11426 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/principal.rb b/app/models/principal.rb index 97babba1c..b6f41d535 100644 --- a/app/models/principal.rb +++ b/app/models/principal.rb @@ -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