diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /app/services/concerns | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'app/services/concerns')
-rw-r--r-- | app/services/concerns/exclusive_lease_guard.rb | 2 | ||||
-rw-r--r-- | app/services/concerns/users/participable_service.rb | 59 |
2 files changed, 46 insertions, 15 deletions
diff --git a/app/services/concerns/exclusive_lease_guard.rb b/app/services/concerns/exclusive_lease_guard.rb index a58e9aefcec..76d59cf2159 100644 --- a/app/services/concerns/exclusive_lease_guard.rb +++ b/app/services/concerns/exclusive_lease_guard.rb @@ -21,7 +21,7 @@ module ExclusiveLeaseGuard lease = exclusive_lease.try_obtain unless lease - log_error("Cannot obtain an exclusive lease for #{self.class.name}. There must be another instance already in execution.") + log_error("Cannot obtain an exclusive lease for #{lease_key}. There must be another instance already in execution.") return end diff --git a/app/services/concerns/users/participable_service.rb b/app/services/concerns/users/participable_service.rb index 4f4032e77b9..c1c93aa604e 100644 --- a/app/services/concerns/users/participable_service.rb +++ b/app/services/concerns/users/participable_service.rb @@ -8,10 +8,14 @@ module Users attr_reader :noteable end + private + def noteable_owner return [] unless noteable && noteable.author.present? - [user_as_hash(noteable.author)] + [noteable.author].tap do |users| + preload_status(users) + end end def participants_in_noteable @@ -22,23 +26,29 @@ module Users end def sorted(users) - users.uniq.to_a.compact.sort_by(&:username).map do |user| - user_as_hash(user) + users.uniq.to_a.compact.sort_by(&:username).tap do |users| + preload_status(users) end end def groups - group_counts = GroupMember - .of_groups(current_user.authorized_groups) - .non_request - .count_users_by_group_id + current_user.authorized_groups.with_route.sort_by(&:path) + end - current_user.authorized_groups.with_route.sort_by(&:path).map do |group| - group_as_hash(group, group_counts) - end + def render_participants_as_hash(participants) + participants.map(&method(:participant_as_hash)) end - private + def participant_as_hash(participant) + case participant + when Group + group_as_hash(participant) + when User + user_as_hash(participant) + else + participant + end + end def user_as_hash(user) { @@ -46,12 +56,11 @@ module Users username: user.username, name: user.name, avatar_url: user.avatar_url, - availability: nil + availability: lazy_user_availability(user).itself # calling #itself to avoid returning a BatchLoader instance } - # Return nil for availability for now due to https://gitlab.com/gitlab-org/gitlab/-/issues/285442 end - def group_as_hash(group, group_counts) + def group_as_hash(group) { type: group.class.name, username: group.full_path, @@ -61,5 +70,27 @@ module Users mentionsDisabled: group.mentions_disabled } end + + def group_counts + @group_counts ||= GroupMember + .of_groups(current_user.authorized_groups) + .non_request + .count_users_by_group_id + end + + def preload_status(users) + users.each { |u| lazy_user_availability(u) } + end + + def lazy_user_availability(user) + BatchLoader.for(user.id).batch do |user_ids, loader| + user_ids.each_slice(1_000) do |sliced_user_ids| + UserStatus + .select(:user_id, :availability) + .primary_key_in(sliced_user_ids) + .each { |status| loader.call(status.user_id, status.availability) } + end + end + end end end |