summaryrefslogtreecommitdiffstats
path: root/app/models/project.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2014-10-25 11:14:16 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2014-10-25 11:14:16 +0000
commit2d64a22dd928be415e0afaa55e43abb9a73ce281 (patch)
tree90c6e1b0383a537f020239377e761ca3267f9301 /app/models/project.rb
parentc0f082ad0252b1da280c0ba61f750046c461976b (diff)
downloadredmine-2d64a22dd928be415e0afaa55e43abb9a73ce281.tar.gz
redmine-2d64a22dd928be415e0afaa55e43abb9a73ce281.zip
Makes Project#assignable_users return a scope that prevents 2*n queries.
git-svn-id: http://svn.redmine.org/redmine/trunk@13509 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/project.rb')
-rw-r--r--app/models/project.rb12
1 files changed, 7 insertions, 5 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 029b12945..aec787284 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -504,15 +504,17 @@ class Project < ActiveRecord::Base
Member.delete_all(['project_id = ?', id])
end
- # Users/groups issues can be assigned to
+ # Return a Principal scope of users/groups issues can be assigned to
def assignable_users
types = ['User']
types << 'Group' if Setting.issue_group_assignment?
- member_principals.
- select {|m| types.include?(m.principal.type) && m.roles.detect(&:assignable?)}.
- map(&:principal).
- sort
+ @assignable_users ||= Principal.
+ active.
+ joins(:members => :roles).
+ where(:type => types, :members => {:project_id => id}, :roles => {:assignable => true}).
+ uniq.
+ sorted
end
# Returns the mail addresses of users that should be always notified on project events