BigW Consortium Gitlab

Commit 9c67f4fb by Stan Hu

Memoize merge request source branches

parent effa94bb
......@@ -7,10 +7,9 @@ module MergeRequests
@branch_name = Gitlab::Git.ref_name(ref)
@fork_merge_requests = @project.fork_merge_requests.opened
@commits = []
@source_merge_requests = merge_requests_for_source_branch
# 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
comment_mr_branch_presence_changed(presence)
else
......@@ -81,7 +80,7 @@ module MergeRequests
# Add comment about branches being deleted or added to merge requests
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(
merge_request, merge_request.project, @current_user,
:source, @branch_name, presence)
......@@ -90,7 +89,7 @@ module MergeRequests
# Add comment about pushing new commits to merge requests
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))
new_commits, existing_commits = @commits.partition do |commit|
......@@ -105,7 +104,7 @@ module MergeRequests
# Call merge request webhook with update branches
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')
end
end
......@@ -115,9 +114,11 @@ module MergeRequests
end
def merge_requests_for_source_branch
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
filter_merge_requests(merge_requests)
@source_merge_requests ||= begin
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
filter_merge_requests(merge_requests)
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