Class: Gitlab::UsageDataCounters::NoteCounter

Inherits:
BaseCounter
  • Object
show all
Defined in:
lib/gitlab/usage_data_counters/note_counter.rb

Constant Summary collapse

KNOWN_EVENTS =
%w[create].freeze
PREFIX =
'note'
COUNTABLE_TYPES =
%w[Snippet Commit MergeRequest].freeze

Constants inherited from BaseCounter

BaseCounter::UnknownEvent

Class Method Summary collapse

Methods included from RedisCounter

#increment, #increment_by, #total_count

Class Method Details

.count(event, noteable_type) ⇒ Object


14
15
16
17
18
# File 'lib/gitlab/usage_data_counters/note_counter.rb', line 14

def count(event, noteable_type)
  return unless countable?(noteable_type)

  increment(redis_key(event, noteable_type))
end

.fallback_totalsObject


32
33
34
# File 'lib/gitlab/usage_data_counters/note_counter.rb', line 32

def fallback_totals
  COUNTABLE_TYPES.map { |counter_key| [counter_key(counter_key), -1] }.to_h
end

.read(event, noteable_type) ⇒ Object


20
21
22
23
24
# File 'lib/gitlab/usage_data_counters/note_counter.rb', line 20

def read(event, noteable_type)
  return 0 unless countable?(noteable_type)

  total_count(redis_key(event, noteable_type))
end

.redis_key(event, noteable_type) ⇒ Object


10
11
12
# File 'lib/gitlab/usage_data_counters/note_counter.rb', line 10

def redis_key(event, noteable_type)
  "#{super(event)}_#{noteable_type}".upcase
end

.totalsObject


26
27
28
29
30
# File 'lib/gitlab/usage_data_counters/note_counter.rb', line 26

def totals
  COUNTABLE_TYPES.map do |countable_type|
    [counter_key(countable_type), read(:create, countable_type)]
  end.to_h
end