1
0
mirror of https://github.com/meineerde/redmine.git synced 2025-12-20 15:31:12 +00:00

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
This commit is contained in:
Jean-Philippe Lang 2014-10-25 11:14:16 +00:00
parent c0f082ad02
commit 2d64a22dd9
2 changed files with 8 additions and 6 deletions

View File

@ -734,7 +734,7 @@ class Issue < ActiveRecord::Base
# Users the issue can be assigned to # Users the issue can be assigned to
def assignable_users def assignable_users
users = project.assignable_users users = project.assignable_users.to_a
users << author if author users << author if author
users << assigned_to if assigned_to users << assigned_to if assigned_to
users.uniq.sort users.uniq.sort

View File

@ -504,15 +504,17 @@ class Project < ActiveRecord::Base
Member.delete_all(['project_id = ?', id]) Member.delete_all(['project_id = ?', id])
end end
# Users/groups issues can be assigned to # Return a Principal scope of users/groups issues can be assigned to
def assignable_users def assignable_users
types = ['User'] types = ['User']
types << 'Group' if Setting.issue_group_assignment? types << 'Group' if Setting.issue_group_assignment?
member_principals. @assignable_users ||= Principal.
select {|m| types.include?(m.principal.type) && m.roles.detect(&:assignable?)}. active.
map(&:principal). joins(:members => :roles).
sort where(:type => types, :members => {:project_id => id}, :roles => {:assignable => true}).
uniq.
sorted
end end
# Returns the mail addresses of users that should be always notified on project events # Returns the mail addresses of users that should be always notified on project events