summaryrefslogtreecommitdiff
path: root/app/workers
diff options
context:
space:
mode:
authorJarka Kadlecova <jarka@gitlab.com>2017-08-01 14:38:45 +0200
committerJarka Kadlecova <jarka@gitlab.com>2017-08-07 15:57:56 +0200
commit9ef3c431e4859e1bc03267735b956d5920d5dd42 (patch)
tree5a4063641e79766c249924f5095e6c328a279846 /app/workers
parentfaa2a123911eaf84bb57163ea7af759d4632601b (diff)
downloadgitlab-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.rb23
-rw-r--r--app/workers/new_issue_worker.rb17
-rw-r--r--app/workers/new_merge_request_worker.rb17
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