From 64bbf64fb6f3b9e89f3180df28c5f06f54638eb8 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 17 Feb 2013 12:41:31 +0000 Subject: [PATCH] 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 --- app/models/principal.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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