Commit 59769fdb940712737656a441ef43a1ad2dd47f4d

Authored by Dmitriy Zaporozhets
1 parent 0bcabdaf

Improve compare logic for EmailOnPush service

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
app/mailers/emails/projects.rb
@@ -17,6 +17,7 @@ module Emails @@ -17,6 +17,7 @@ module Emails
17 def repository_push_email(project_id, recipient, author_id, branch, compare) 17 def repository_push_email(project_id, recipient, author_id, branch, compare)
18 @project = Project.find(project_id) 18 @project = Project.find(project_id)
19 @author = User.find(author_id) 19 @author = User.find(author_id)
  20 + @compare = compare
20 @commits = Commit.decorate(compare.commits) 21 @commits = Commit.decorate(compare.commits)
21 @diffs = compare.diffs 22 @diffs = compare.diffs
22 @branch = branch 23 @branch = branch
app/views/notify/repository_push_email.html.haml
@@ -21,3 +21,8 @@ @@ -21,3 +21,8 @@
21 %pre 21 %pre
22 = diff.diff 22 = diff.diff
23 %br 23 %br
  24 +
  25 +- if @compare.timeout
  26 + %h5 Huge diff. To prevent performance issues it was hidden
  27 +- elsif @compare.commits_over_limit?
  28 + %h5 Diff for big amount of commits is disabled
app/views/notify/repository_push_email.text.haml
@@ -18,3 +18,8 @@ Diff: @@ -18,3 +18,8 @@ Diff:
18 = diff.new_path || diff.old_path 18 = diff.new_path || diff.old_path
19 \===================================== 19 \=====================================
20 = diff.diff 20 = diff.diff
  21 +\
  22 +- if @compare.timeout
  23 + Huge diff. To prevent performance issues it was hidden
  24 +- elsif @compare.commits_over_limit?
  25 + Diff for big amount of commits is disabled
app/workers/emails_on_push_worker.rb
@@ -13,13 +13,13 @@ class EmailsOnPushWorker @@ -13,13 +13,13 @@ class EmailsOnPushWorker
13 return true 13 return true
14 end 14 end
15 15
16 - compare = Gitlab::Git::Compare.new(project.repository.raw_repository, before_sha, after_sha) 16 + compare = Gitlab::Git::Compare.new(project.repository.raw_repository, before_sha, after_sha, MergeRequestDiff::COMMITS_SAFE_SIZE)
17 17
18 # Do not send emails if git compare failed 18 # Do not send emails if git compare failed
19 return false unless compare && compare.commits.present? 19 return false unless compare && compare.commits.present?
20 20
21 recipients.split(" ").each do |recipient| 21 recipients.split(" ").each do |recipient|
22 - Notify.delay.repository_push_email(project_id, recipient, author_id, branch, compare) 22 + Notify.repository_push_email(project_id, recipient, author_id, branch, compare).deliver
23 end 23 end
24 end 24 end
25 end 25 end