diff options
author | Douwe Maan <douwe@gitlab.com> | 2017-11-30 12:09:50 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2017-11-30 12:09:50 +0300 |
commit | 73e48b745c34c048c56abf28e6c278707d9bd2f3 (patch) | |
tree | 01aa9a7a3abcfaf7bebbdec7e84aa0f628f292cd | |
parent | 1aaa6095a2d8890df73731a8af3d26158a198743 (diff) | |
parent | 4925ec50877c9bf1338d41a7676b3644f18370f7 (diff) |
Merge branch 'use-count_commits-directly' into 'master'
Count the commits directly
See merge request gitlab-org/gitlab-ce!15628
-rw-r--r-- | app/models/merge_request.rb | 3 | ||||
-rw-r--r-- | changelogs/unreleased/use-count_commits-directly.yml | 5 | ||||
-rw-r--r-- | lib/gitlab/git/repository.rb | 2 |
3 files changed, 8 insertions, 2 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index e232feaeada..bbc01e9677c 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -899,7 +899,8 @@ class MergeRequest < ActiveRecord::Base def compute_diverged_commits_count return 0 unless source_branch_sha && target_branch_sha - Gitlab::Git::Commit.between(target_project.repository.raw_repository, source_branch_sha, target_branch_sha).size + target_project.repository + .count_commits_between(source_branch_sha, target_branch_sha) end private :compute_diverged_commits_count diff --git a/changelogs/unreleased/use-count_commits-directly.yml b/changelogs/unreleased/use-count_commits-directly.yml new file mode 100644 index 00000000000..549e0744ea4 --- /dev/null +++ b/changelogs/unreleased/use-count_commits-directly.yml @@ -0,0 +1,5 @@ +--- +title: Improve the performance for counting commits +merge_request: 15628 +author: +type: performance diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index d399636bb28..fb9c3e92d3f 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -505,7 +505,7 @@ module Gitlab # Counts the amount of commits between `from` and `to`. def count_commits_between(from, to) - Commit.between(self, from, to).size + count_commits(ref: "#{from}..#{to}") end # Returns the SHA of the most recent common ancestor of +from+ and +to+ |