Commit 5219f392 authored by Marc Shaw's avatar Marc Shaw

Code review: Freeze hash and change class to module

Issue: gitlab.com/gitlab-org/gitlab/-/issues/219956
Merge Request: gitlab.com/gitlab-org/gitlab/-/merge_requests/35580
parent 5d523107
...@@ -577,11 +577,10 @@ module Gitlab ...@@ -577,11 +577,10 @@ module Gitlab
{ analytics_unique_visits: results } { analytics_unique_visits: results }
end end
# rubocop: disable CodeReuse/ActiveRecord
def action_monthly_active_users(time_period) def action_monthly_active_users(time_period)
return {} unless Feature.enabled?(Gitlab::UsageDataCounters::TrackUniqueActions::FEATURE_FLAG) return {} unless Feature.enabled?(Gitlab::UsageDataCounters::TrackUniqueActions::FEATURE_FLAG)
counter = Gitlab::UsageDataCounters::TrackUniqueActions.new counter = Gitlab::UsageDataCounters::TrackUniqueActions
project_count = redis_usage_data do project_count = redis_usage_data do
counter.count_unique_events( counter.count_unique_events(
...@@ -613,7 +612,6 @@ module Gitlab ...@@ -613,7 +612,6 @@ module Gitlab
action_monthly_active_users_wiki_repo: wiki_count action_monthly_active_users_wiki_repo: wiki_count
} }
end end
# rubocop: enable CodeReuse/ActiveRecord
private private
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
module Gitlab module Gitlab
module UsageDataCounters module UsageDataCounters
class TrackUniqueActions module TrackUniqueActions
KEY_EXPIRY_LENGTH = 29.days KEY_EXPIRY_LENGTH = 29.days
FEATURE_FLAG = :track_unique_actions FEATURE_FLAG = :track_unique_actions
...@@ -24,16 +24,9 @@ module Gitlab ...@@ -24,16 +24,9 @@ module Gitlab
project: { project: {
pushed: PUSH_ACTION pushed: PUSH_ACTION
} }
}) }).freeze
def self.track_action(params)
self.new.track_action(params)
end
def self.count_unique_events(params)
self.new.count_unique_events(params)
end
class << self
def track_action(event_action:, event_target:, author_id:, time: Time.zone.now) def track_action(event_action:, event_target:, author_id:, time: Time.zone.now)
return unless Gitlab::CurrentSettings.usage_ping_enabled return unless Gitlab::CurrentSettings.usage_ping_enabled
return unless Feature.enabled?(FEATURE_FLAG) return unless Feature.enabled?(FEATURE_FLAG)
...@@ -89,4 +82,5 @@ module Gitlab ...@@ -89,4 +82,5 @@ module Gitlab
end end
end end
end end
end
end end
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Gitlab::UsageDataCounters::TrackUniqueActions, :clean_gitlab_redis_shared_state do RSpec.describe Gitlab::UsageDataCounters::TrackUniqueActions, :clean_gitlab_redis_shared_state do
subject(:track_unique_events) { described_class.new } subject(:track_unique_events) { described_class }
let(:time) { Time.zone.now } let(:time) { Time.zone.now }
......
...@@ -905,7 +905,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -905,7 +905,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
let(:feature_flag) { true } let(:feature_flag) { true }
before do before do
counter = Gitlab::UsageDataCounters::TrackUniqueActions.new counter = Gitlab::UsageDataCounters::TrackUniqueActions
project = Event::TARGET_TYPES[:project] project = Event::TARGET_TYPES[:project]
wiki = Event::TARGET_TYPES[:wiki] wiki = Event::TARGET_TYPES[:wiki]
design = Event::TARGET_TYPES[:design] design = Event::TARGET_TYPES[:design]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment