Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2017-11-28 16:43:31 +0300
committerLin Jen-Shin <godfat@godfat.org>2017-11-30 11:03:28 +0300
commit4925ec50877c9bf1338d41a7676b3644f18370f7 (patch)
treeacf74aa4177d87d74be41921eda1a41d8ac5b94e
parent17c53d7d0dcc6739691f1298ddd0c254c9614571 (diff)
We could simply count the commits
-rw-r--r--app/models/merge_request.rb3
-rw-r--r--changelogs/unreleased/use-count_commits-directly.yml5
-rw-r--r--lib/gitlab/git/repository.rb2
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+