diff options
author | Grzegorz Bizon <grzegorz@gitlab.com> | 2019-03-28 12:03:38 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzegorz@gitlab.com> | 2019-03-28 12:03:38 +0300 |
commit | 8d07bc9c9f6846a2675c299953312a6ccfed4362 (patch) | |
tree | 80272c148310fef69a4afac15dee1ebfb95df8f3 /app/services/concerns/users/participable_service.rb | |
parent | 0540cb6b070579715c56942a7c92e4ba74920ebe (diff) | |
parent | c5f9b2be826c05e5f06d424f5c110976ad0b68c4 (diff) |
Merge branch 'fix-routes-n-plus-one-in-user-autocomplete' into 'master'
Remove N+1 queries from users autocomplete
See merge request gitlab-org/gitlab-ce!26491
Diffstat (limited to 'app/services/concerns/users/participable_service.rb')
-rw-r--r-- | app/services/concerns/users/participable_service.rb | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/app/services/concerns/users/participable_service.rb b/app/services/concerns/users/participable_service.rb index 6713b6617ae..a3cc6014fd3 100644 --- a/app/services/concerns/users/participable_service.rb +++ b/app/services/concerns/users/participable_service.rb @@ -28,19 +28,35 @@ module Users end def groups - current_user.authorized_groups.sort_by(&:path).map do |group| - group_as_hash(group) + group_counts = GroupMember + .in_groups(current_user.authorized_groups) + .non_request + .count_users_by_group_id + + current_user.authorized_groups.with_route.sort_by(&:path).map do |group| + group_as_hash(group, group_counts) end end private def user_as_hash(user) - { type: user.class.name, username: user.username, name: user.name, avatar_url: user.avatar_url } + { + type: user.class.name, + username: user.username, + name: user.name, + avatar_url: user.avatar_url + } end - def group_as_hash(group) - { type: group.class.name, username: group.full_path, name: group.full_name, avatar_url: group.avatar_url, count: group.users.count } + def group_as_hash(group, group_counts) + { + type: group.class.name, + username: group.full_path, + name: group.full_name, + avatar_url: group.avatar_url, + count: group_counts.fetch(group.id, 0) + } end end end |