]> source.dussan.org Git - redmine.git/commitdiff
Makes Project#assignable_users return a scope that prevents 2*n queries.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 25 Oct 2014 11:14:16 +0000 (11:14 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 25 Oct 2014 11:14:16 +0000 (11:14 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@13509 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/issue.rb
app/models/project.rb

index 78854568a4f3ca14e8c80d41f8a397d02094f691..22c09ab650b0c245bfa897dd8aa0cea6e8642ddb 100644 (file)
@@ -734,7 +734,7 @@ class Issue < ActiveRecord::Base
 
   # Users the issue can be assigned to
   def assignable_users
-    users = project.assignable_users
+    users = project.assignable_users.to_a
     users << author if author
     users << assigned_to if assigned_to
     users.uniq.sort
index 029b129452bb183c0ffd12267d6c524f1e2b7cc9..aec78728433e51ed61663b005cb0bef9a0c8f12e 100644 (file)
@@ -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