gitlab-org--gitlab-foss/lib/gitlab/usage_data_counters/note_counter.rb
Bob Van Landuyt 71691d935e Count comments on notes and merge requests
This extends our existing `Gitlab::UsageDataCounters::NoteCounter` to
also count notes on commits and merge requests
2019-08-16 18:54:42 +02:00

39 lines
947 B
Ruby

# frozen_string_literal: true
module Gitlab::UsageDataCounters
class NoteCounter < BaseCounter
KNOWN_EVENTS = %w[create].freeze
PREFIX = 'note'
COUNTABLE_TYPES = %w[Snippet Commit MergeRequest].freeze
class << self
def redis_key(event, noteable_type)
"#{super(event)}_#{noteable_type}".upcase
end
def count(event, noteable_type)
return unless countable?(noteable_type)
increment(redis_key(event, noteable_type))
end
def read(event, noteable_type)
return 0 unless countable?(noteable_type)
total_count(redis_key(event, noteable_type))
end
def totals
COUNTABLE_TYPES.map do |countable_type|
[:"#{countable_type.underscore}_comment", read(:create, countable_type)]
end.to_h
end
private
def countable?(noteable_type)
COUNTABLE_TYPES.include?(noteable_type.to_s)
end
end
end
end