Merge branch 'use-count_commits-directly' into 'master'

Count the commits directly

See merge request gitlab-org/gitlab-ce!15628
This commit is contained in:
Douwe Maan 2017-11-30 09:09:50 +00:00
commit 73e48b745c
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+