Class: SnippetStatistics

Inherits:
ApplicationRecord show all
Includes:
AfterCommitQueue, UpdateProjectStatistics
Defined in:
app/models/snippet_statistics.rb

Instance Method Summary collapse

Methods included from AfterCommitQueue

#run_after_commit, #run_after_commit_or_now

Methods inherited from ApplicationRecord

at_most, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, underscore, without_order

Instance Method Details

#refresh!Object


36
37
38
39
40
41
42
# File 'app/models/snippet_statistics.rb', line 36

def refresh!
  update_commit_count
  update_repository_size
  update_file_count

  save!
end

#update_commit_countObject


18
19
20
# File 'app/models/snippet_statistics.rb', line 18

def update_commit_count
  self.commit_count = repository.commit_count
end

#update_file_countObject


26
27
28
29
30
31
32
33
34
# File 'app/models/snippet_statistics.rb', line 26

def update_file_count
  count = if snippet.repository_exists?
            repository.ls_files(repository.root_ref).size
          else
            0
          end

  self.file_count = count
end

#update_repository_sizeObject


22
23
24
# File 'app/models/snippet_statistics.rb', line 22

def update_repository_size
  self.repository_size = repository.size.megabytes
end