diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
commit | b76ae638462ab0f673e5915986070518dd3f9ad3 (patch) | |
tree | bdab0533383b52873be0ec0eb4d3c66598ff8b91 /lib/gitlab/git/commit_stats.rb | |
parent | 434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff) |
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'lib/gitlab/git/commit_stats.rb')
-rw-r--r-- | lib/gitlab/git/commit_stats.rb | 24 |
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 |