summaryrefslogtreecommitdiff
path: root/app/models/merge_request.rb
diff options
context:
space:
mode:
authorAlejandro Rodríguez <alejorro70@gmail.com>2018-03-06 00:03:48 -0300
committerAlejandro Rodríguez <alejorro70@gmail.com>2018-03-06 16:05:34 -0300
commitbc365bd15a0ec0317a4fce71d024397f26ab56c5 (patch)
tree74e8dce48c7430583033375c303fa54eb40ab5aa /app/models/merge_request.rb
parent49f72d06654bd7bdea259154e1092a53aab57acc (diff)
downloadgitlab-ce-bc365bd15a0ec0317a4fce71d024397f26ab56c5.tar.gz
Use persisted/memoized value for MRs shas instead of doing git lookups
Diffstat (limited to 'app/models/merge_request.rb')
-rw-r--r--app/models/merge_request.rb20
1 files changed, 16 insertions, 4 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 5bec68ce4f6..9a7e66a9cbb 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -375,15 +375,27 @@ class MergeRequest < ActiveRecord::Base
end
def diff_start_sha
- diff_start_commit.try(:sha)
+ if persisted?
+ merge_request_diff.start_commit_sha
+ else
+ target_branch_head.try(:sha)
+ end
end
def diff_base_sha
- diff_base_commit.try(:sha)
+ if persisted?
+ merge_request_diff.base_commit_sha
+ else
+ branch_merge_base_commit.try(:sha)
+ end
end
def diff_head_sha
- diff_head_commit.try(:sha)
+ if persisted?
+ merge_request_diff.head_commit_sha
+ else
+ source_branch_head.try(:sha)
+ end
end
# When importing a pull request from GitHub, the old and new branches may no
@@ -646,7 +658,7 @@ class MergeRequest < ActiveRecord::Base
!ProtectedBranch.protected?(source_project, source_branch) &&
!source_project.root_ref?(source_branch) &&
Ability.allowed?(current_user, :push_code, source_project) &&
- diff_head_commit == source_branch_head
+ diff_head_sha == source_branch_head.try(:sha)
end
def should_remove_source_branch?