blob: 63248ef07c94798538756562d34e68ca5692756f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# frozen_string_literal: true
module Packages
class CreateEventService < BaseService
def execute
if Feature.enabled?(:collect_package_events_redis, default_enabled: true)
::Packages::Event.unique_counters_for(event_scope, event_name, originator_type).each do |event_name|
::Gitlab::UsageDataCounters::HLLRedisCounter.track_event(event_name, values: current_user.id)
end
::Packages::Event.counters_for(event_scope, event_name, originator_type).each do |event_name|
::Gitlab::UsageDataCounters::PackageEventCounter.count(event_name)
end
end
if Feature.enabled?(:collect_package_events) && Gitlab::Database.read_write?
::Packages::Event.create!(
event_type: event_name,
originator: current_user&.id,
originator_type: originator_type,
event_scope: event_scope
)
end
end
private
def event_scope
@event_scope ||= scope.is_a?(::Packages::Package) ? scope.package_type : scope
end
def scope
params[:scope]
end
def event_name
params[:event_name]
end
def originator_type
case current_user
when User
:user
when DeployToken
:deploy_token
else
:guest
end
end
def guest?
originator_type == :guest
end
end
end
|