Commit a96dc944 authored by Alfredo Sumaran's avatar Alfredo Sumaran Committed by Jacob Schatz

Memoize target

parent 1eeabdc6
module Projects module Projects
class ParticipantsService < BaseService class ParticipantsService < BaseService
def execute(noteable_type, noteable_id) def execute(noteable_type, noteable_id)
@target = get_target(noteable_type, noteable_id) @noteable_type = noteable_type
participating = @noteable_id = noteable_id
if noteable_type && noteable_id
participants_in_target
else
[]
end
project_members = sorted(project.team.members) project_members = sorted(project.team.members)
participants = target_owner + participating + all_members + groups + project_members participants = target_owner + participants_in_target + all_members + groups + project_members
participants.uniq participants.uniq
end end
def get_target(type, id) def target
case type @target ||=
when "Issue" case @noteable_type
project.issues.find_by_iid(id) when "Issue"
when "MergeRequest" project.issues.find_by_iid(@noteable_id)
project.merge_requests.find_by_iid(id) when "MergeRequest"
when "Commit" project.merge_requests.find_by_iid(@noteable_id)
project.commit(id) when "Commit"
end project.commit(@noteable_id)
else
nil
end
end end
def target_owner def target_owner
return [] unless @target && @target.author.present? return [] unless target && target.author.present?
[{ [{
name: @target.author.name, name: target.author.name,
username: @target.author.username username: target.author.username
}] }]
end end
def participants_in_target def participants_in_target
return [] unless @target return [] unless target
users = @target.participants(current_user) users = target.participants(current_user)
sorted(users) sorted(users)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment