Speed up generation of commit stats by using Rugged native methods
The previous implementation iterated across the entire patch set to determine the number of lines added, deleted, and changed. Rugged has a native method `Rugged::Diff#stat` that does this already, which appears to be a little faster and require less RAM than doing this ourselves. Improves performance in #41524
This commit is contained in:
parent
ff077cf7dc
commit
25a868753b
3 changed files with 12 additions and 7 deletions
5
changelogs/unreleased/sh-optimize-commit-stats.yml
Normal file
5
changelogs/unreleased/sh-optimize-commit-stats.yml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: Speed up generation of commit stats by using Rugged native methods
|
||||||
|
merge_request:
|
||||||
|
author:
|
||||||
|
type: performance
|
|
@ -34,13 +34,8 @@ module Gitlab
|
||||||
|
|
||||||
def rugged_stats(commit)
|
def rugged_stats(commit)
|
||||||
diff = commit.rugged_diff_from_parent
|
diff = commit.rugged_diff_from_parent
|
||||||
|
_files_changed, @additions, @deletions = diff.stat
|
||||||
diff.each_patch do |p|
|
@total = @additions + @deletions
|
||||||
# TODO: Use the new Rugged convenience methods when they're released
|
|
||||||
@additions += p.stat[0]
|
|
||||||
@deletions += p.stat[1]
|
|
||||||
@total += p.changes
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -428,6 +428,11 @@ describe Gitlab::Git::Commit, seed_helper: true do
|
||||||
subject { super().deletions }
|
subject { super().deletions }
|
||||||
it { is_expected.to eq(6) }
|
it { is_expected.to eq(6) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#total' do
|
||||||
|
subject { super().total }
|
||||||
|
it { is_expected.to eq(17) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#stats with gitaly on' do
|
describe '#stats with gitaly on' do
|
||||||
|
|
Loading…
Reference in a new issue