b5042e5301
The NotificationService has to do quite a lot of work to calculate the recipients for an email. Where possible, we should try to avoid doing this in an HTTP request, because the mail are sent by Sidekiq anyway, so there's no need to schedule those emails immediately. This commit creates a generic Sidekiq worker that uses Global ID to serialise and deserialise its arguments, then forwards them to the NotificationService. The NotificationService gains an `#async` method, so you can replace: notification_service.new_issue(issue, current_user) With: notification_service.async.new_issue(issue, current_user) And have everything else work as normal, except that calculating the recipients will be done by Sidekiq, which will then schedule further Sidekiq jobs to send each email.
45 lines
1.6 KiB
Ruby
45 lines
1.6 KiB
Ruby
module Issues
|
|
class CloseService < Issues::BaseService
|
|
# Closes the supplied issue if the current user is able to do so.
|
|
def execute(issue, commit: nil, notifications: true, system_note: true)
|
|
return issue unless can?(current_user, :update_issue, issue)
|
|
|
|
close_issue(issue,
|
|
commit: commit,
|
|
notifications: notifications,
|
|
system_note: system_note)
|
|
end
|
|
|
|
# Closes the supplied issue without checking if the user is authorized to
|
|
# do so.
|
|
#
|
|
# The code calling this method is responsible for ensuring that a user is
|
|
# allowed to close the given issue.
|
|
def close_issue(issue, commit: nil, notifications: true, system_note: true)
|
|
if project.jira_tracker? && project.jira_service.active && issue.is_a?(ExternalIssue)
|
|
project.jira_service.close_issue(commit, issue)
|
|
todo_service.close_issue(issue, current_user)
|
|
return issue
|
|
end
|
|
|
|
if project.issues_enabled? && issue.close
|
|
issue.update(closed_by: current_user)
|
|
event_service.close_issue(issue, current_user)
|
|
create_note(issue, commit) if system_note
|
|
notification_service.async.close_issue(issue, current_user) if notifications
|
|
todo_service.close_issue(issue, current_user)
|
|
execute_hooks(issue, 'close')
|
|
invalidate_cache_counts(issue, users: issue.assignees)
|
|
issue.update_project_counter_caches
|
|
end
|
|
|
|
issue
|
|
end
|
|
|
|
private
|
|
|
|
def create_note(issue, current_commit)
|
|
SystemNoteService.change_status(issue, issue.project, current_user, issue.state, current_commit)
|
|
end
|
|
end
|
|
end
|