summaryrefslogtreecommitdiff
path: root/app/services/git
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2019-08-16 20:26:38 +0000
committerStan Hu <stanhu@gmail.com>2019-08-16 20:26:38 +0000
commit971e040c00a14d7fbdfed5f45d6978a2c6b4f4f5 (patch)
tree0562c25e5219edb26736f2cd6a888f1cbc0b222f /app/services/git
parent504ed1c4a44f3b86ce2ce1a545236c8c0f84c17f (diff)
parent97c2564ffac057f1830d008269f90afa9e12f815 (diff)
downloadgitlab-ce-971e040c00a14d7fbdfed5f45d6978a2c6b4f4f5.tar.gz
Merge branch 'dm-process-commit-worker-n+1' into 'master'
Look up upstream commits once before queuing ProcessCommitWorkers Closes #65464 See merge request gitlab-org/gitlab-ce!31871
Diffstat (limited to 'app/services/git')
-rw-r--r--app/services/git/branch_hooks_service.rb25
1 files changed, 23 insertions, 2 deletions
diff --git a/app/services/git/branch_hooks_service.rb b/app/services/git/branch_hooks_service.rb
index 431a5aedf2e..d2b037a680c 100644
--- a/app/services/git/branch_hooks_service.rb
+++ b/app/services/git/branch_hooks_service.rb
@@ -83,8 +83,16 @@ module Git
# Schedules processing of commit messages
def enqueue_process_commit_messages
- limited_commits.each do |commit|
- next unless commit.matches_cross_reference_regex?
+ referencing_commits = limited_commits.select(&:matches_cross_reference_regex?)
+
+ upstream_commit_ids = upstream_commit_ids(referencing_commits)
+
+ referencing_commits.each do |commit|
+ # Avoid reprocessing commits that already exist upstream if the project
+ # is a fork. This will prevent duplicated/superfluous system notes on
+ # mentionables referenced by a commit that is pushed to the upstream,
+ # that is then also pushed to forks when these get synced by users.
+ next if upstream_commit_ids.include?(commit.id)
ProcessCommitWorker.perform_async(
project.id,
@@ -142,5 +150,18 @@ module Git
def branch_name
strong_memoize(:branch_name) { Gitlab::Git.ref_name(params[:ref]) }
end
+
+ def upstream_commit_ids(commits)
+ set = Set.new
+
+ upstream_project = project.fork_source
+ if upstream_project
+ upstream_project
+ .commits_by(oids: commits.map(&:id))
+ .each { |commit| set << commit.id }
+ end
+
+ set
+ end
end
end