diff options
author | Adam Niedzielski <adamsunday@gmail.com> | 2016-12-01 14:17:30 +0300 |
---|---|---|
committer | Adam Niedzielski <adamsunday@gmail.com> | 2016-12-01 14:17:30 +0300 |
commit | cb6f8cdfc23a18daf33288c95ae8badec63f53ad (patch) | |
tree | cad717c7ba416e3fc7974c833cff154d3a1449a2 /app/models/merge_request.rb | |
parent | 2adc6568a6f94b2844c95a0b699a0be9bb8980d1 (diff) |
Replace references to MergeRequestDiff#commits with st_commits
when we care only about the number of commits
We do not have to instantiate all objects in this case.
Diffstat (limited to 'app/models/merge_request.rb')
-rw-r--r-- | app/models/merge_request.rb | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 64990f8134e..bfb016df46d 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -22,7 +22,8 @@ class MergeRequest < ActiveRecord::Base after_create :ensure_merge_request_diff, unless: :importing? after_update :reload_diff_if_branch_changed - delegate :commits, :real_size, to: :merge_request_diff, prefix: nil + delegate :commits, :real_size, :commits_sha, :commits_count, + to: :merge_request_diff, prefix: nil # When this attribute is true some MR validation is ignored # It allows us to close or modify broken merge requests @@ -662,7 +663,7 @@ class MergeRequest < ActiveRecord::Base end def broken? - self.commits.blank? || branch_missing? || cannot_be_merged? + has_no_commits? || branch_missing? || cannot_be_merged? end def can_be_merged_by?(user) @@ -770,10 +771,6 @@ class MergeRequest < ActiveRecord::Base diverged_commits_count > 0 end - def commits_sha - commits.map(&:sha) - end - def head_pipeline return unless diff_head_sha && source_project @@ -871,4 +868,12 @@ class MergeRequest < ActiveRecord::Base @conflicts_can_be_resolved_in_ui = false end end + + def has_commits? + commits_count > 0 + end + + def has_no_commits? + !has_commits? + end end |