blob: c5498ce530fdb5838750b45061002cea2dcec3ed (
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
56
57
|
# frozen_string_literal: true
module Gitlab
module Usage
module Metrics
module Instrumentations
class CountImportedProjectsMetric < DatabaseMetric
operation :count
def initialize(time_frame:, options: {})
super
raise ArgumentError, "import_type options attribute is required" unless import_type.present?
end
relation { ::Project }
start do |time_constraints|
unless time_constraints.nil?
start = time_constraints[:created_at]&.first
unless start.nil?
::Project
.select(:id)
.where(Project.arel_table[:created_at].gteq(start)) # rubocop:disable UsageData/LargeTable
.order(created_at: :asc).limit(1).first&.id
end
end
end
finish do |time_constraints|
unless time_constraints.nil?
finish = time_constraints[:created_at]&.last
unless finish.nil?
::Project
.select(:id)
.where(Project.arel_table[:created_at].lteq(finish)) # rubocop:disable UsageData/LargeTable
.order(created_at: :desc).limit(1).first&.id
end
end
end
private
def relation
super.imported_from(import_type) # rubocop: disable CodeReuse/ActiveRecord
end
def import_type
options[:import_type]
end
end
end
end
end
end
|