Class: Packages::Event

Inherits:
ApplicationRecord show all
Defined in:
app/models/packages/event.rb

Constant Summary collapse

UNIQUE_EVENTS_ALLOWED =
%i[push_package delete_package pull_package pull_symbol_package push_symbol_package].freeze
EVENT_SCOPES =
::Packages::Package.package_types.merge(container: 1000, tag: 1001, dependency_proxy: 1002).freeze
EVENT_PREFIX =
"i_package"

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Class Method Summary collapse

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from SensitiveSerializableHash

#serializable_hash

Class Method Details

.counters_for(event_scope, event_type, originator_type) ⇒ Object

total counter names for tracking number of events


52
53
54
55
56
57
58
59
60
# File 'app/models/packages/event.rb', line 52

def self.counters_for(event_scope, event_type, originator_type)
  return [] unless event_allowed?(event_type)

  [
    "#{EVENT_PREFIX}_#{event_type}",
    "#{EVENT_PREFIX}_#{event_type}_by_#{originator_type}",
    "#{EVENT_PREFIX}_#{event_scope}_#{event_type}"
  ]
end

.event_allowed?(event_type) ⇒ Boolean

Remove some of the events, for now, so we don't hammer Redis too hard. See: gitlab.com/gitlab-org/gitlab/-/issues/280770

Returns:

  • (Boolean)

37
38
39
40
41
# File 'app/models/packages/event.rb', line 37

def self.event_allowed?(event_type)
  return true if UNIQUE_EVENTS_ALLOWED.include?(event_type.to_sym)

  false
end

.unique_counters_for(event_scope, event_type, originator_type) ⇒ Object

counter names for unique user tracking (for MAU)


44
45
46
47
48
49
# File 'app/models/packages/event.rb', line 44

def self.unique_counters_for(event_scope, event_type, originator_type)
  return [] unless event_allowed?(event_type)
  return [] if originator_type.to_s == 'guest'

  ["#{EVENT_PREFIX}_#{event_scope}_#{originator_type}"]
end