Class: Gitlab::GithubImport::ObjectCounter

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/github_import/object_counter.rb

Constant Summary collapse

OPERATIONS =
%w[fetched imported].freeze
PROJECT_COUNTER_LIST_KEY =
'github-importer/object-counters-list/%{project}/%{operation}'
PROJECT_COUNTER_KEY =
'github-importer/object-counter/%{project}/%{operation}/%{object_type}'
EMPTY_SUMMARY =
OPERATIONS.index_with { |operation| {} }
GLOBAL_COUNTER_KEY =
'github_importer_%{operation}_%{object_type}'
GLOBAL_COUNTER_DESCRIPTION =
'The number of %{operation} Github %{object_type}'
CACHING =
Gitlab::Cache::Import::Caching
IMPORT_CACHING_TIMEOUT =
2.weeks.to_i

Class Method Summary collapse

Class Method Details

.increment(project, object_type, operation, value: 1) ⇒ Object

Increments the project and the global counters if the given value is >= 1



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gitlab/github_import/object_counter.rb', line 21

def increment(project, object_type, operation, value: 1)
  integer = value.to_i

  return if integer <= 0

  validate_operation!(operation)

  increment_project_counter(project, object_type, operation, integer)
  increment_global_counter(object_type, operation, integer)

  project.import_state&.expire_etag_cache
end

.summary(project) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/gitlab/github_import/object_counter.rb', line 34

def summary(project)
  cached_summary = cashed_summary(project)
  # Actual information about objects that have already been imported is stored
  # in the Redis Cache until Redis key is expired.
  # After import is completed we store this information in project's import_checksums
  return cached_summary if cached_summary != EMPTY_SUMMARY || project.import_state.blank?

  project.import_state.completed? ? project.import_checksums : cached_summary
end