diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2014-05-24 10:41:13 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2014-05-24 10:41:13 +0000 |
commit | 8aeab43247f9c246edac565c25fa03d4b295504c (patch) | |
tree | 41aa6b938f8d30d557d4b4869dbcda8e810307f4 /app/controllers/groups_controller.rb | |
parent | cdf9cae4a2cfa0504c236cf43ab795d9c0e984ee (diff) | |
download | redmine-8aeab43247f9c246edac565c25fa03d4b295504c.tar.gz redmine-8aeab43247f9c246edac565c25fa03d4b295504c.zip |
Count users with a single query on group list (#16905).
git-svn-id: http://svn.redmine.org/redmine/trunk@13149 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers/groups_controller.rb')
-rw-r--r-- | app/controllers/groups_controller.rb | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 2dbcd8a1f..0cd4055e5 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -26,9 +26,10 @@ class GroupsController < ApplicationController def index @groups = Group.sorted.all - respond_to do |format| - format.html + format.html { + @user_count_by_group_id = user_count_by_group_id + } format.api end end @@ -138,4 +139,12 @@ class GroupsController < ApplicationController rescue ActiveRecord::RecordNotFound render_404 end + + def user_count_by_group_id + h = User.joins(:groups).group('group_id').count + h.keys.each do |key| + h[key.to_i] = h.delete(key) + end + h + end end |