diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-10 12:10:08 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-10 12:10:08 +0300 |
commit | 5adf6557e251c047ed68bac28cfecf9491ee6b41 (patch) | |
tree | a7ea2924ef96ccf36a915ddaf686f5f6e1e75b00 /app/models/concerns/analytics | |
parent | 0adc81d8e0c7b291fd7fdef33a4ea9c01b4852ce (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/concerns/analytics')
-rw-r--r-- | app/models/concerns/analytics/cycle_analytics/stage.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/app/models/concerns/analytics/cycle_analytics/stage.rb b/app/models/concerns/analytics/cycle_analytics/stage.rb index 2a0274f5706..7bb6004ca83 100644 --- a/app/models/concerns/analytics/cycle_analytics/stage.rb +++ b/app/models/concerns/analytics/cycle_analytics/stage.rb @@ -10,6 +10,7 @@ module Analytics included do belongs_to :start_event_label, class_name: 'GroupLabel', optional: true belongs_to :end_event_label, class_name: 'GroupLabel', optional: true + belongs_to :stage_event_hash, class_name: 'Analytics::CycleAnalytics::StageEventHash', foreign_key: :stage_event_hash_id, optional: true validates :name, presence: true validates :name, exclusion: { in: Gitlab::Analytics::CycleAnalytics::DefaultStages.names }, if: :custom? @@ -28,6 +29,9 @@ module Analytics scope :ordered, -> { order(:relative_position, :id) } scope :for_list, -> { includes(:start_event_label, :end_event_label).ordered } scope :by_value_stream, -> (value_stream) { where(value_stream_id: value_stream.id) } + + before_save :ensure_stage_event_hash_id + after_commit :cleanup_old_stage_event_hash end def parent=(_) @@ -133,6 +137,20 @@ module Analytics .id_in(label_id) .exists? end + + def ensure_stage_event_hash_id + previous_stage_event_hash = stage_event_hash&.hash_sha256 + + if previous_stage_event_hash.blank? || events_hash_code != previous_stage_event_hash + self.stage_event_hash_id = Analytics::CycleAnalytics::StageEventHash.record_id_by_hash_sha256(events_hash_code) + end + end + + def cleanup_old_stage_event_hash + if stage_event_hash_id_previously_changed? && stage_event_hash_id_previously_was + Analytics::CycleAnalytics::StageEventHash.cleanup_if_unused(stage_event_hash_id_previously_was) + end + end end end end |