diff options
author | Rémy Coutable <remy@rymai.me> | 2017-09-22 17:46:24 +0200 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-10-05 10:48:25 +0200 |
commit | 67de21c15bd8bb24667a4d8bfa259406165a909e (patch) | |
tree | f445198728e3c86ef92e02268e38c1294fe95c6d | |
parent | 43b75b38086c88894fca4b6c1c9e68c111c4e546 (diff) | |
download | gitlab-ce-67de21c15bd8bb24667a4d8bfa259406165a909e.tar.gz |
Move `fetch_ref` from MergeRequestDiff#ensure_commit_shas to MergeRequest
MergeRequest#create_merge_request_diff and MergeRequest#reload_diff are
the only places where we generate a new MR diff so that's where we
should fetch the ref.
This also ensures that the ref is not fetched when we call
merge_request.merge_request_diffs.create in
Github::Import#fetch_pull_requests.
Signed-off-by: Rémy Coutable <remy@rymai.me>
-rw-r--r-- | app/models/merge_request.rb | 3 | ||||
-rw-r--r-- | app/models/merge_request_diff.rb | 2 |
2 files changed, 3 insertions, 2 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 0ba00d447e8..086226618e6 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -415,6 +415,8 @@ class MergeRequest < ActiveRecord::Base end def create_merge_request_diff + fetch_ref + # n+1: https://gitlab.com/gitlab-org/gitlab-ce/issues/37435 Gitlab::GitalyClient.allow_n_plus_1_calls do merge_request_diffs.create @@ -462,6 +464,7 @@ class MergeRequest < ActiveRecord::Base return unless open? old_diff_refs = self.diff_refs + create_merge_request_diff MergeRequests::MergeRequestDiffCacheService.new.execute(self) new_diff_refs = self.diff_refs diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb index 68c87210772..faf0b95f842 100644 --- a/app/models/merge_request_diff.rb +++ b/app/models/merge_request_diff.rb @@ -55,8 +55,6 @@ class MergeRequestDiff < ActiveRecord::Base end def ensure_commit_shas - merge_request.fetch_ref - self.start_commit_sha ||= merge_request.target_branch_sha self.head_commit_sha ||= merge_request.source_branch_sha self.base_commit_sha ||= find_base_sha |