Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/analytics/cycle_analytics/stage.rb')
-rw-r--r--app/models/analytics/cycle_analytics/stage.rb54
1 files changed, 54 insertions, 0 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..7e9a89975a3
--- /dev/null
+++ b/app/models/analytics/cycle_analytics/stage.rb
@@ -0,0 +1,54 @@
+# 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)
+ # Looking up the whole hierarchy including all kinds (type) of Namespace records.
+ # We're doing a custom traversal_ids query because:
+ # - The traversal_ids based `self_and_descendants` doesn't include the ProjectNamespace records.
+ # - The default recursive lookup also excludes the ProjectNamespace records.
+ #
+ # Related issue: https://gitlab.com/gitlab-org/gitlab/-/issues/386124
+ all_namespace_ids =
+ Namespace
+ .select(Arel.sql('namespaces.traversal_ids[array_length(namespaces.traversal_ids, 1)]').as('id'))
+ .where("traversal_ids @> ('{?}')", namespace.id)
+
+ with_preloaded_labels
+ .where(parent_id: all_namespace_ids)
+ .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