summaryrefslogtreecommitdiff
path: root/lib/gitlab/git/commit_stats.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/git/commit_stats.rb')
-rw-r--r--lib/gitlab/git/commit_stats.rb24
1 files changed, 13 insertions, 11 deletions
diff --git a/lib/gitlab/git/commit_stats.rb b/lib/gitlab/git/commit_stats.rb
index 8815088d23c..6a7a7032665 100644
--- a/lib/gitlab/git/commit_stats.rb
+++ b/lib/gitlab/git/commit_stats.rb
@@ -14,21 +14,23 @@ module Gitlab
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/323
def initialize(repo, commit)
@id = commit.id
- @additions = 0
- @deletions = 0
- @total = 0
- wrapped_gitaly_errors do
- gitaly_stats(repo, commit)
- end
- end
+ additions, deletions = fetch_stats(repo, commit)
- def gitaly_stats(repo, commit)
- stats = repo.gitaly_commit_client.commit_stats(@id)
- @additions = stats.additions
- @deletions = stats.deletions
+ @additions = additions.to_i
+ @deletions = deletions.to_i
@total = @additions + @deletions
end
+
+ def fetch_stats(repo, commit)
+ Rails.cache.fetch("commit_stats:#{repo.gl_project_path}:#{@id}") do
+ stats = wrapped_gitaly_errors do
+ repo.gitaly_commit_client.commit_stats(@id)
+ end
+
+ [stats.additions, stats.deletions]
+ end
+ end
end
end
end