Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Kalderimis <akalderimis@gitlab.com>2019-07-21 04:26:19 +0300
committerDouwe Maan <douwe@gitlab.com>2019-07-21 04:26:19 +0300
commit7320758611b8d8c28fb179f970e015a72357b94d (patch)
treec74e9e90c6f0fd35f5b3cf08466c2947b39128ca /lib/gitlab/usage_data_counters/wiki_page_counter.rb
parent66394bd1b7c98d7a6abbeade068b8b9c1b838ddf (diff)
Count wiki page creation
This adds a counter to count page creation, which is reflected in the usage-data we collect. The number created is stored in Redis, avoiding DB access.
Diffstat (limited to 'lib/gitlab/usage_data_counters/wiki_page_counter.rb')
-rw-r--r--lib/gitlab/usage_data_counters/wiki_page_counter.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/gitlab/usage_data_counters/wiki_page_counter.rb b/lib/gitlab/usage_data_counters/wiki_page_counter.rb
new file mode 100644
index 00000000000..c8b59a3160c
--- /dev/null
+++ b/lib/gitlab/usage_data_counters/wiki_page_counter.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+module Gitlab::UsageDataCounters
+ class WikiPageCounter
+ extend RedisCounter
+
+ KNOWN_EVENTS = %w[create update delete].map(&:freeze).freeze
+
+ UnknownEvent = Class.new(StandardError)
+
+ class << self
+ # Each event gets a unique Redis key
+ def redis_key(event)
+ raise UnknownEvent, event unless KNOWN_EVENTS.include?(event.to_s)
+
+ "USAGE_WIKI_PAGES_#{event}".upcase
+ end
+
+ def count(event)
+ increment(redis_key event)
+ end
+
+ def read(event)
+ total_count(redis_key event)
+ end
+
+ def totals
+ KNOWN_EVENTS.map { |e| ["wiki_pages_#{e}".to_sym, read(e)] }.to_h
+ end
+ end
+ end
+end