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
This commit is contained in:
Jean-Philippe Lang
2014-05-24 10:41:13 +00:00
parent cdf9cae4a2
commit 8aeab43247
3 changed files with 19 additions and 5 deletions

View File

@@ -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