summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTiago Botelho <tiagonbotelho@hotmail.com>2018-10-02 16:33:43 +0100
committerTiago Botelho <tiagonbotelho@hotmail.com>2018-10-03 11:34:48 +0100
commit1e662293e8fc2f2eba9657dd27449e966736a14a (patch)
tree564290907477e5fee4ebabf2ad75fcc44086c938 /lib
parent9b2e17ac71ee446da0f34dada41401803af816c7 (diff)
downloadgitlab-ce-1e662293e8fc2f2eba9657dd27449e966736a14a.tar.gz
Implements Web IDE commits counter in Redis
This makes a temporary implementation of the Web IDE commits counter using Redis while https://gitlab.com/gitlab-org/gitlab-ce/issues/52096 is being discussed further for a more generic approach to counters
Diffstat (limited to 'lib')
-rw-r--r--lib/api/commits.rb2
-rw-r--r--lib/gitlab/usage_data.rb4
-rw-r--r--lib/gitlab/web_ide_commits_counter.rb17
3 files changed, 21 insertions, 2 deletions
diff --git a/lib/api/commits.rb b/lib/api/commits.rb
index e16dd29d138..ec44936d114 100644
--- a/lib/api/commits.rb
+++ b/lib/api/commits.rb
@@ -109,7 +109,7 @@ module API
if result[:status] == :success
commit_detail = user_project.repository.commit(result[:result])
- UsageCounters.first_or_create.increment_counters(:web_ide_commits) if find_user_from_warden
+ Gitlab::WebIdeCommitsCounter.increment if find_user_from_warden
present commit_detail, with: Entities::CommitDetail
else
diff --git a/lib/gitlab/usage_data.rb b/lib/gitlab/usage_data.rb
index afab36e89dd..5097c3253c9 100644
--- a/lib/gitlab/usage_data.rb
+++ b/lib/gitlab/usage_data.rb
@@ -108,7 +108,9 @@ module Gitlab
end
def usage_counters
- UsageCounters.first_or_create.totals
+ {
+ web_ide_commits: Gitlab::WebIdeCommitsCounter.total_count
+ }
end
def components_usage_data
diff --git a/lib/gitlab/web_ide_commits_counter.rb b/lib/gitlab/web_ide_commits_counter.rb
new file mode 100644
index 00000000000..1cd9b5295b9
--- /dev/null
+++ b/lib/gitlab/web_ide_commits_counter.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module WebIdeCommitsCounter
+ WEB_IDE_COMMITS_KEY = "WEB_IDE_COMMITS_COUNT".freeze
+
+ class << self
+ def increment
+ Gitlab::Redis::SharedState.with { |redis| redis.incr(WEB_IDE_COMMITS_KEY) }
+ end
+
+ def total_count
+ Gitlab::Redis::SharedState.with { |redis| redis.get(WEB_IDE_COMMITS_KEY).to_i }
+ end
+ end
+ end
+end