Skip to content

Commit

Permalink
use group_concat when fetching member list
Browse files Browse the repository at this point in the history
  • Loading branch information
giosakti committed Dec 31, 2018
1 parent c351ad1 commit aed305f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/models/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,15 @@ def self.get_sysadmins_and_groups sysadmins, default_admins = true
select(:user_login_id).
where("id IN (?)", sysadmins).
collect(&:user_login_id)

# TODO: extract to query object
groups = Group.
select(%Q(
id,
name,
gid,
(
SELECT user_login_id
SELECT GROUP_CONCAT(user_login_id)
FROM users
INNER JOIN group_associations
ON users.id = group_associations.user_id
Expand All @@ -137,7 +139,7 @@ def self.get_sysadmins_and_groups sysadmins, default_admins = true
)).
where("name IN (?)", sysadmins_login_ids).
map{ |group|
members = (group.members.is_a? Array) ? group.members : [group.members]
members = group.members.split(',')
Group.generate_group_response(group.name, group.gid, members)
}
groups << Group.get_default_sysadmin_group_for_host(sysadmins_login_ids, default_admins)
Expand Down

0 comments on commit aed305f

Please sign in to comment.