summaryrefslogtreecommitdiff
path: root/app/models/merge_request.rb
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-02-07 22:23:15 -0800
committerSean McGivern <sean@gitlab.com>2018-02-08 10:28:50 +0000
commit9a323c7e1f806bca099158e29561e0958baa06a6 (patch)
tree585b09782d8c48283d6bd4819e29ace7f2aea98c /app/models/merge_request.rb
parent828357fb828fc2d07b201f4f97f22ef964ab6a89 (diff)
downloadgitlab-ce-9a323c7e1f806bca099158e29561e0958baa06a6.tar.gz
Memoize MergeRequest#rebase_in_progress? to prevent N+1 queries in Gitalysh-fix-rebase-in-progress-nplus-one
MergeRequest#rebase_in_progress? and MergeRequest#rebase_path were called twice each time per request. This memoization helps reduce the overall number of queries. See https://gitlab.com/gitlab-org/gitlab-ee/-/jobs/51616319 as a failing job. Closes gitlab-org/gitlab-ee#4857
Diffstat (limited to 'app/models/merge_request.rb')
-rw-r--r--app/models/merge_request.rb8
1 files changed, 5 insertions, 3 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index d025062f562..5bec68ce4f6 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -158,10 +158,12 @@ class MergeRequest < ActiveRecord::Base
end
def rebase_in_progress?
- # The source project can be deleted
- return false unless source_project
+ strong_memoize(:rebase_in_progress) do
+ # The source project can be deleted
+ next false unless source_project
- source_project.repository.rebase_in_progress?(id)
+ source_project.repository.rebase_in_progress?(id)
+ end
end
# Use this method whenever you need to make sure the head_pipeline is synced with the