From b263ab618c59ff9e377780c6120ab60fd97aefd0 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Thu, 4 Feb 2016 16:30:33 +0100 Subject: [PATCH] Dedicated method for counting commits between refs gitlab_git 8.1 adds the ability to count the amount of commits between two references without having to allocate anything but regular Rugged::Commit objects. This in turn speeds up the process of counting the number of commits a branch is ahead/behind by about 3.5x. --- Gemfile | 2 +- Gemfile.lock | 4 ++-- app/models/repository.rb | 7 +++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index a06dbe8e061..08fb9216e9f 100644 --- a/Gemfile +++ b/Gemfile @@ -50,7 +50,7 @@ gem "browser", '~> 1.0.0' # Extracting information from a git repository # Provide access to Gitlab::Git library -gem "gitlab_git", '~> 8.0.0' +gem "gitlab_git", '~> 8.1' # LDAP Auth # GitLab fork with several improvements to original library. For full list of changes diff --git a/Gemfile.lock b/Gemfile.lock index bd767016108..88496163c89 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -357,7 +357,7 @@ GEM posix-spawn (~> 0.3) gitlab_emoji (0.2.0) gemojione (~> 2.1) - gitlab_git (8.0.0) + gitlab_git (8.1.0) activesupport (~> 4.0) charlock_holmes (~> 0.7.3) github-linguist (~> 4.7.0) @@ -933,7 +933,7 @@ DEPENDENCIES github-markup (~> 1.3.1) gitlab-flowdock-git-hook (~> 1.0.1) gitlab_emoji (~> 0.2.0) - gitlab_git (~> 8.0.0) + gitlab_git (~> 8.1) gitlab_meta (= 7.0) gitlab_omniauth-ldap (~> 1.2.1) gollum-lib (~> 4.1.0) diff --git a/app/models/repository.rb b/app/models/repository.rb index 130daddd9d1..e813c946bc1 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -184,8 +184,11 @@ class Repository cache.fetch(:"diverging_commit_counts_#{branch.name}") do # Rugged seems to throw a `ReferenceError` when given branch_names rather # than SHA-1 hashes - number_commits_behind = commits_between(branch.target, root_ref_hash).size - number_commits_ahead = commits_between(root_ref_hash, branch.target).size + number_commits_behind = raw_repository. + count_commits_between(branch.target, root_ref_hash) + + number_commits_ahead = raw_repository. + count_commits_between(root_ref_hash, branch.target) { behind: number_commits_behind, ahead: number_commits_ahead } end