summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2018-01-03 17:39:24 +0000
committerRobert Speicher <robert@gitlab.com>2018-01-03 17:39:24 +0000
commit946a3634bc5a851944e5cc7fe8fdb5341ca5176b (patch)
tree9f524c93d227e92f272435f9443f5fd1a23bea31
parentf7cb21930abaaa94118c1981149010abdd62de1a (diff)
parent25a868753b4b9e673af31f7f4f58f9e97811e9d9 (diff)
downloadgitlab-ce-946a3634bc5a851944e5cc7fe8fdb5341ca5176b.tar.gz
Merge branch 'sh-optimize-commit-stats' into 'master'
Speed up generation of commit stats by using Rugged native methods See merge request gitlab-org/gitlab-ce!16186
-rw-r--r--changelogs/unreleased/sh-optimize-commit-stats.yml5
-rw-r--r--lib/gitlab/git/commit_stats.rb9
-rw-r--r--spec/lib/gitlab/git/commit_spec.rb5
3 files changed, 12 insertions, 7 deletions
diff --git a/changelogs/unreleased/sh-optimize-commit-stats.yml b/changelogs/unreleased/sh-optimize-commit-stats.yml
new file mode 100644
index 00000000000..8c1be1252fb
--- /dev/null
+++ b/changelogs/unreleased/sh-optimize-commit-stats.yml
@@ -0,0 +1,5 @@
+---
+title: Speed up generation of commit stats by using Rugged native methods
+merge_request:
+author:
+type: performance
diff --git a/lib/gitlab/git/commit_stats.rb b/lib/gitlab/git/commit_stats.rb
index 6bf49a0af18..8463b1eb794 100644
--- a/lib/gitlab/git/commit_stats.rb
+++ b/lib/gitlab/git/commit_stats.rb
@@ -34,13 +34,8 @@ module Gitlab
def rugged_stats(commit)
diff = commit.rugged_diff_from_parent
-
- diff.each_patch do |p|
- # TODO: Use the new Rugged convenience methods when they're released
- @additions += p.stat[0]
- @deletions += p.stat[1]
- @total += p.changes
- end
+ _files_changed, @additions, @deletions = diff.stat
+ @total = @additions + @deletions
end
end
end
diff --git a/spec/lib/gitlab/git/commit_spec.rb b/spec/lib/gitlab/git/commit_spec.rb
index 5ed639543e0..6d35734d306 100644
--- a/spec/lib/gitlab/git/commit_spec.rb
+++ b/spec/lib/gitlab/git/commit_spec.rb
@@ -428,6 +428,11 @@ describe Gitlab::Git::Commit, seed_helper: true do
subject { super().deletions }
it { is_expected.to eq(6) }
end
+
+ describe '#total' do
+ subject { super().total }
+ it { is_expected.to eq(17) }
+ end
end
describe '#stats with gitaly on' do