We could simply count the commits

This commit is contained in:
Lin Jen-Shin 2017-11-28 21:43:31 +08:00
parent 17c53d7d0d
commit 4925ec5087
3 changed files with 8 additions and 2 deletions

View File

@ -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

View File

@ -0,0 +1,5 @@
---
title: Improve the performance for counting commits
merge_request: 15628
author:
type: performance

View File

@ -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+