Commit 9c67f4fb authored by Stan Hu's avatar Stan Hu

Memoize merge request source branches

parent effa94bb
...@@ -7,10 +7,9 @@ module MergeRequests ...@@ -7,10 +7,9 @@ module MergeRequests
@branch_name = Gitlab::Git.ref_name(ref) @branch_name = Gitlab::Git.ref_name(ref)
@fork_merge_requests = @project.fork_merge_requests.opened @fork_merge_requests = @project.fork_merge_requests.opened
@commits = [] @commits = []
@source_merge_requests = merge_requests_for_source_branch
# Leave a system note if a branch were deleted/added # Leave a system note if a branch were deleted/added
if Gitlab::Git.blank_ref?(oldrev) or Gitlab::Git.blank_ref?(newrev) if Gitlab::Git.blank_ref?(oldrev) || Gitlab::Git.blank_ref?(newrev)
presence = Gitlab::Git.blank_ref?(oldrev) ? :add : :delete presence = Gitlab::Git.blank_ref?(oldrev) ? :add : :delete
comment_mr_branch_presence_changed(presence) comment_mr_branch_presence_changed(presence)
else else
...@@ -81,7 +80,7 @@ module MergeRequests ...@@ -81,7 +80,7 @@ module MergeRequests
# Add comment about branches being deleted or added to merge requests # Add comment about branches being deleted or added to merge requests
def comment_mr_branch_presence_changed(presence) def comment_mr_branch_presence_changed(presence)
@source_merge_requests.each do |merge_request| merge_requests_for_source_branch.each do |merge_request|
SystemNoteService.change_branch_presence( SystemNoteService.change_branch_presence(
merge_request, merge_request.project, @current_user, merge_request, merge_request.project, @current_user,
:source, @branch_name, presence) :source, @branch_name, presence)
...@@ -90,7 +89,7 @@ module MergeRequests ...@@ -90,7 +89,7 @@ module MergeRequests
# Add comment about pushing new commits to merge requests # Add comment about pushing new commits to merge requests
def comment_mr_with_commits def comment_mr_with_commits
@source_merge_requests.each do |merge_request| merge_requests_for_source_branch.each do |merge_request|
mr_commit_ids = Set.new(merge_request.commits.map(&:id)) mr_commit_ids = Set.new(merge_request.commits.map(&:id))
new_commits, existing_commits = @commits.partition do |commit| new_commits, existing_commits = @commits.partition do |commit|
...@@ -105,7 +104,7 @@ module MergeRequests ...@@ -105,7 +104,7 @@ module MergeRequests
# Call merge request webhook with update branches # Call merge request webhook with update branches
def execute_mr_web_hooks def execute_mr_web_hooks
@source_merge_requests.each do |merge_request| merge_requests_for_source_branch.each do |merge_request|
execute_hooks(merge_request, 'update') execute_hooks(merge_request, 'update')
end end
end end
...@@ -115,9 +114,11 @@ module MergeRequests ...@@ -115,9 +114,11 @@ module MergeRequests
end end
def merge_requests_for_source_branch def merge_requests_for_source_branch
@source_merge_requests ||= begin
merge_requests = @project.origin_merge_requests.opened.where(source_branch: @branch_name).to_a merge_requests = @project.origin_merge_requests.opened.where(source_branch: @branch_name).to_a
merge_requests += @fork_merge_requests.where(source_branch: @branch_name).to_a merge_requests += @fork_merge_requests.where(source_branch: @branch_name).to_a
filter_merge_requests(merge_requests) filter_merge_requests(merge_requests)
end end
end end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment