diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 01:45:44 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 01:45:44 +0000 |
commit | 85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch) | |
tree | 9160f299afd8c80c038f08e1545be119f5e3f1e1 /app/models/analytics | |
parent | 15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff) | |
download | gitlab-ce-85dc423f7090da0a52c73eb66faf22ddb20efff9.tar.gz |
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'app/models/analytics')
-rw-r--r-- | app/models/analytics/instance_statistics.rb | 9 | ||||
-rw-r--r-- | app/models/analytics/instance_statistics/measurement.rb | 31 |
2 files changed, 40 insertions, 0 deletions
diff --git a/app/models/analytics/instance_statistics.rb b/app/models/analytics/instance_statistics.rb new file mode 100644 index 00000000000..df7b26e4fa6 --- /dev/null +++ b/app/models/analytics/instance_statistics.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module Analytics + module InstanceStatistics + def self.table_name_prefix + 'analytics_instance_statistics_' + end + end +end diff --git a/app/models/analytics/instance_statistics/measurement.rb b/app/models/analytics/instance_statistics/measurement.rb new file mode 100644 index 00000000000..eaaf9e999b3 --- /dev/null +++ b/app/models/analytics/instance_statistics/measurement.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +module Analytics + module InstanceStatistics + class Measurement < ApplicationRecord + enum identifier: { + projects: 1, + users: 2, + issues: 3, + merge_requests: 4, + groups: 5, + pipelines: 6 + } + + IDENTIFIER_QUERY_MAPPING = { + identifiers[:projects] => -> { Project }, + identifiers[:users] => -> { User }, + identifiers[:issues] => -> { Issue }, + identifiers[:merge_requests] => -> { MergeRequest }, + identifiers[:groups] => -> { Group }, + identifiers[:pipelines] => -> { Ci::Pipeline } + }.freeze + + validates :recorded_at, :identifier, :count, presence: true + validates :recorded_at, uniqueness: { scope: :identifier } + + scope :order_by_latest, -> { order(recorded_at: :desc) } + scope :with_identifier, -> (identifier) { where(identifier: identifier) } + end + end +end |