diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index e232feaeada641a3930b11bb0909c68e833bae54..bbc01e9677c5b887220549f7f7ebe75d81ddac14 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 0000000000000000000000000000000000000000..549e0744ea447ae8fe676d942f0220392a9b393c --- /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 d399636bb284651876b00c7afb15afdd7b392365..fb9c3e92d3f470372bce8efc6c995a165a1e8aa2 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+