diff options
author | Jarka Kadlecova <jarka@gitlab.com> | 2017-08-01 14:38:45 +0200 |
---|---|---|
committer | Jarka Kadlecova <jarka@gitlab.com> | 2017-08-07 15:57:56 +0200 |
commit | 9ef3c431e4859e1bc03267735b956d5920d5dd42 (patch) | |
tree | 5a4063641e79766c249924f5095e6c328a279846 /app/workers | |
parent | faa2a123911eaf84bb57163ea7af759d4632601b (diff) | |
download | gitlab-ce-9ef3c431e4859e1bc03267735b956d5920d5dd42.tar.gz |
Move some after_create parts to worker to improve performance32844-issuables-performance
Diffstat (limited to 'app/workers')
-rw-r--r-- | app/workers/concerns/new_issuable.rb | 23 | ||||
-rw-r--r-- | app/workers/new_issue_worker.rb | 17 | ||||
-rw-r--r-- | app/workers/new_merge_request_worker.rb | 17 |
3 files changed, 57 insertions, 0 deletions
diff --git a/app/workers/concerns/new_issuable.rb b/app/workers/concerns/new_issuable.rb new file mode 100644 index 00000000000..3fd472bf0c1 --- /dev/null +++ b/app/workers/concerns/new_issuable.rb @@ -0,0 +1,23 @@ +module NewIssuable + attr_reader :issuable, :user + + def ensure_objects_found(issuable_id, user_id) + @issuable = issuable_class.find_by(id: issuable_id) + unless @issuable + log_error(issuable_class, issuable_id) + return false + end + + @user = User.find_by(id: user_id) + unless @user + log_error(User, user_id) + return false + end + + true + end + + def log_error(record_class, record_id) + Rails.logger.error("#{self.class}: couldn't find #{record_class} with ID=#{record_id}, skipping job") + end +end diff --git a/app/workers/new_issue_worker.rb b/app/workers/new_issue_worker.rb new file mode 100644 index 00000000000..19a778ad522 --- /dev/null +++ b/app/workers/new_issue_worker.rb @@ -0,0 +1,17 @@ +class NewIssueWorker + include Sidekiq::Worker + include DedicatedSidekiqQueue + include NewIssuable + + def perform(issue_id, user_id) + return unless ensure_objects_found(issue_id, user_id) + + EventCreateService.new.open_issue(issuable, user) + NotificationService.new.new_issue(issuable, user) + issuable.create_cross_references!(user) + end + + def issuable_class + Issue + end +end diff --git a/app/workers/new_merge_request_worker.rb b/app/workers/new_merge_request_worker.rb new file mode 100644 index 00000000000..3c8a68016ff --- /dev/null +++ b/app/workers/new_merge_request_worker.rb @@ -0,0 +1,17 @@ +class NewMergeRequestWorker + include Sidekiq::Worker + include DedicatedSidekiqQueue + include NewIssuable + + def perform(merge_request_id, user_id) + return unless ensure_objects_found(merge_request_id, user_id) + + EventCreateService.new.open_mr(issuable, user) + NotificationService.new.new_merge_request(issuable, user) + issuable.create_cross_references!(user) + end + + def issuable_class + MergeRequest + end +end |