diff options
author | Stan Hu <stanhu@gmail.com> | 2015-10-15 12:24:30 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2015-10-16 09:54:13 +0300 |
commit | 9c67f4fb51719116737f9812d312f20eefebeacd (patch) | |
tree | 82e44b8b705d5da5a9bceb54b397fd5925d6e9da /app | |
parent | effa94bb878f4e9c208640c0f067b20cc004db2c (diff) |
Memoize merge request source branches
Diffstat (limited to 'app')
-rw-r--r-- | app/services/merge_requests/refresh_service.rb | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/app/services/merge_requests/refresh_service.rb b/app/services/merge_requests/refresh_service.rb index fd15889343e..0362b2d0ea9 100644 --- a/app/services/merge_requests/refresh_service.rb +++ b/app/services/merge_requests/refresh_service.rb @@ -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 |