diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-24 21:11:44 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-24 21:11:44 +0300 |
commit | fd247970cfe1e98276c780fbdcca026b7960e42a (patch) | |
tree | ab7963eb9b30fd73283c526cb6ae4ca1ef61c06f /app/models/analytics | |
parent | df9890e9a702e2f12bbc8f022b916ca72820a292 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/analytics')
-rw-r--r-- | app/models/analytics/cycle_analytics/stage.rb | 43 | ||||
-rw-r--r-- | app/models/analytics/cycle_analytics/stage_event_hash.rb | 11 | ||||
-rw-r--r-- | app/models/analytics/cycle_analytics/value_stream.rb | 47 |
3 files changed, 98 insertions, 3 deletions
diff --git a/app/models/analytics/cycle_analytics/stage.rb b/app/models/analytics/cycle_analytics/stage.rb new file mode 100644 index 00000000000..fb9918e195d --- /dev/null +++ b/app/models/analytics/cycle_analytics/stage.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +module Analytics + module CycleAnalytics + class Stage < ApplicationRecord + self.table_name = :analytics_cycle_analytics_group_stages + + include DatabaseEventTracking + include Analytics::CycleAnalytics::Stageable + include Analytics::CycleAnalytics::Parentable + + validates :name, uniqueness: { scope: [:group_id, :group_value_stream_id] } + belongs_to :value_stream, class_name: 'Analytics::CycleAnalytics::ValueStream', +foreign_key: :group_value_stream_id, inverse_of: :stages + + alias_attribute :parent, :namespace + alias_attribute :parent_id, :group_id + alias_attribute :value_stream_id, :group_value_stream_id + + def self.distinct_stages_within_hierarchy(namespace) + with_preloaded_labels + .where(group_id: namespace.self_and_descendants.select(:id)) + .select("DISTINCT ON(stage_event_hash_id) #{quoted_table_name}.*") + end + + SNOWPLOW_ATTRIBUTES = %i[ + id + created_at + updated_at + relative_position + start_event_identifier + end_event_identifier + group_id + start_event_label_id + end_event_label_id + hidden + custom + name + group_value_stream_id + ].freeze + end + end +end diff --git a/app/models/analytics/cycle_analytics/stage_event_hash.rb b/app/models/analytics/cycle_analytics/stage_event_hash.rb index 0e1e9b3ef67..043a5d45e3d 100644 --- a/app/models/analytics/cycle_analytics/stage_event_hash.rb +++ b/app/models/analytics/cycle_analytics/stage_event_hash.rb @@ -4,6 +4,7 @@ module Analytics module CycleAnalytics class StageEventHash < ApplicationRecord has_many :cycle_analytics_project_stages, class_name: 'Analytics::CycleAnalytics::ProjectStage', inverse_of: :stage_event_hash + has_many :cycle_analytics_stages, class_name: 'Analytics::CycleAnalytics::Stage', inverse_of: :stage_event_hash validates :hash_sha256, presence: true @@ -33,10 +34,14 @@ module Analytics end def self.unused_hashes_for(id) - exists_query = Analytics::CycleAnalytics::ProjectStage.where(stage_event_hash_id: id).select('1').limit(1) - where.not('EXISTS (?)', exists_query) + project_stage_exists_query = Analytics::CycleAnalytics::ProjectStage.where(stage_event_hash_id: id).select('1').limit(1) + stage_exists_query = ::Analytics::CycleAnalytics::Stage.where(stage_event_hash_id: id).select('1').limit(1) + + where + .not('EXISTS (?)', project_stage_exists_query) + .where + .not('EXISTS (?)', stage_exists_query) end end end end -Analytics::CycleAnalytics::StageEventHash.prepend_mod_with('Analytics::CycleAnalytics::StageEventHash') diff --git a/app/models/analytics/cycle_analytics/value_stream.rb b/app/models/analytics/cycle_analytics/value_stream.rb new file mode 100644 index 00000000000..3d8a0a53f5e --- /dev/null +++ b/app/models/analytics/cycle_analytics/value_stream.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +module Analytics + module CycleAnalytics + class ValueStream < ApplicationRecord + self.table_name = :analytics_cycle_analytics_group_value_streams + + include Analytics::CycleAnalytics::Parentable + + has_many :stages, -> { ordered }, + class_name: 'Analytics::CycleAnalytics::Stage', + foreign_key: :group_value_stream_id, + index_errors: true, + inverse_of: :value_stream + + validates :name, presence: true + validates :name, length: { minimum: 3, maximum: 100, allow_nil: false }, uniqueness: { scope: :group_id } + + accepts_nested_attributes_for :stages, allow_destroy: true + + scope :preload_associated_models, -> { + includes(:namespace, + stages: [ + :namespace, + :end_event_label, + :start_event_label + ]) + } + + after_save :ensure_aggregation_record_presence + + def custom? + persisted? || name != Analytics::CycleAnalytics::Stages::BaseService::DEFAULT_VALUE_STREAM_NAME + end + + def self.build_default_value_stream(namespace) + new(name: Analytics::CycleAnalytics::Stages::BaseService::DEFAULT_VALUE_STREAM_NAME, namespace: namespace) + end + + private + + def ensure_aggregation_record_presence + Analytics::CycleAnalytics::Aggregation.safe_create_for_namespace(namespace) + end + end + end +end |