mirror of
https://github.com/redmine/redmine.git
synced 2025-11-07 05:45:49 +01:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user