Class: Gitlab::Git::CommitStats
- Inherits:
-
Object
- Object
- Gitlab::Git::CommitStats
- Includes:
- WrapsGitalyErrors
- Defined in:
- lib/gitlab/git/commit_stats.rb
Instance Attribute Summary collapse
-
#additions ⇒ Object
readonly
Returns the value of attribute additions.
-
#deletions ⇒ Object
readonly
Returns the value of attribute deletions.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
- #ensure_stats_format(repo) ⇒ Object
- #fetch_stats(repo) ⇒ Object
-
#initialize(repo, commit) ⇒ CommitStats
constructor
Instantiate a CommitStats object.
Methods included from WrapsGitalyErrors
Constructor Details
#initialize(repo, commit) ⇒ CommitStats
Instantiate a CommitStats object
Gitaly migration: gitlab.com/gitlab-org/gitaly/issues/323
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/gitlab/git/commit_stats.rb', line 15 def initialize(repo, commit) @id = commit.id additions, deletions, files = ensure_stats_format(repo) @additions = additions.to_i @deletions = deletions.to_i @files = files.to_i @total = @additions + @deletions end |
Instance Attribute Details
#additions ⇒ Object (readonly)
Returns the value of attribute additions.
10 11 12 |
# File 'lib/gitlab/git/commit_stats.rb', line 10 def additions @additions end |
#deletions ⇒ Object (readonly)
Returns the value of attribute deletions.
10 11 12 |
# File 'lib/gitlab/git/commit_stats.rb', line 10 def deletions @deletions end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
10 11 12 |
# File 'lib/gitlab/git/commit_stats.rb', line 10 def files @files end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
10 11 12 |
# File 'lib/gitlab/git/commit_stats.rb', line 10 def id @id end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
10 11 12 |
# File 'lib/gitlab/git/commit_stats.rb', line 10 def total @total end |
Instance Method Details
#ensure_stats_format(repo) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/gitlab/git/commit_stats.rb', line 26 def ensure_stats_format(repo) cached_stats = fetch_stats(repo) if cached_stats.length == 2 Rails.cache.delete(cache_key(repo)) cached_stats = fetch_stats(repo) end cached_stats end |
#fetch_stats(repo) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/gitlab/git/commit_stats.rb', line 37 def fetch_stats(repo) Rails.cache.fetch(cache_key(repo)) do stats = wrapped_gitaly_errors do repo.gitaly_commit_client.commit_stats(@id) end [stats.additions, stats.deletions, stats.files] end end |