diff options
author | micael.bergeron <micaelbergeron@gmail.com> | 2017-11-01 17:31:35 +0300 |
---|---|---|
committer | micael.bergeron <micaelbergeron@gmail.com> | 2017-11-03 15:13:11 +0300 |
commit | cd88fa8f80710ec977a85ab8701570073c94f017 (patch) | |
tree | 8866f616741d7a3f7f35f6e37b2e01503804b2a2 /app/models/merge_request.rb | |
parent | 8c01f3110c8d8601fc16b17850dfa778f1f3d877 (diff) |
removed the #ensure_ref_fetched from all controllers
also, I refactored the MergeRequest#fetch_ref method to express
the side-effect that this method has.
MergeRequest#fetch_ref -> MergeRequest#fetch_ref!
Repository#fetch_source_branch -> Repository#fetch_source_branch!
Diffstat (limited to 'app/models/merge_request.rb')
-rw-r--r-- | app/models/merge_request.rb | 27 |
1 files changed, 3 insertions, 24 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 3133dc9e7eb..ccad8e102aa 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -426,7 +426,7 @@ class MergeRequest < ActiveRecord::Base end def create_merge_request_diff - fetch_ref + fetch_ref! # n+1: https://gitlab.com/gitlab-org/gitlab-ce/issues/37435 Gitlab::GitalyClient.allow_n_plus_1_calls do @@ -811,29 +811,14 @@ class MergeRequest < ActiveRecord::Base end end - def fetch_ref - write_ref - update_column(:ref_fetched, true) + def fetch_ref! + target_project.repository.fetch_source_branch!(source_project.repository, source_branch, ref_path) end def ref_path "refs/#{Repository::REF_MERGE_REQUEST}/#{iid}/head" end - def ref_fetched? - super || - begin - computed_value = project.repository.ref_exists?(ref_path) - update_column(:ref_fetched, true) if computed_value - - computed_value - end - end - - def ensure_ref_fetched - fetch_ref unless ref_fetched? - end - def in_locked_state begin lock_mr @@ -975,10 +960,4 @@ class MergeRequest < ActiveRecord::Base project.merge_requests.merged.where(author_id: author_id).empty? end - - private - - def write_ref - target_project.repository.fetch_source_branch(source_project.repository, source_branch, ref_path) - end end |