diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2010-03-21 09:28:24 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2010-03-21 09:28:24 +0000 |
commit | 5225fb70f533c992bd50435096ebd2bfb1c3e942 (patch) | |
tree | 13728b77568be299f5eb7abde38750d8f35081e1 /app/models | |
parent | e584ae220da7fa15d089889d4db066b73e8f7da6 (diff) | |
download | redmine-5225fb70f533c992bd50435096ebd2bfb1c3e942.tar.gz redmine-5225fb70f533c992bd50435096ebd2bfb1c3e942.zip |
Optimize retrieval of user's projects members.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3607 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/query.rb | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/app/models/query.rb b/app/models/query.rb index c223654f1..ae162b0a7 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -185,9 +185,11 @@ class Query < ActiveRecord::Base if project user_values += project.users.sort.collect{|s| [s.name, s.id.to_s] } else - # members of the user's projects - # OPTIMIZE: Is selecting from users per project (N+1) - user_values += User.current.projects.collect(&:users).flatten.uniq.sort.collect{|s| [s.name, s.id.to_s] } + project_ids = User.current.projects.collect(&:id) + if project_ids.any? + # members of the user's projects + user_values += User.active.find(:all, :conditions => ["#{User.table_name}.id IN (SELECT DISTINCT user_id FROM members WHERE project_id IN (?))", project_ids]).sort.collect{|s| [s.name, s.id.to_s] } + end end @available_filters["assigned_to_id"] = { :type => :list_optional, :order => 4, :values => user_values } unless user_values.empty? @available_filters["author_id"] = { :type => :list, :order => 5, :values => user_values } unless user_values.empty? |