diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-07 15:16:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-07 15:16:11 +0300 |
commit | e8e22b384c97899e6944eeb85a0a2b84e8615f9c (patch) | |
tree | 1c0624d28d4d65d1674a28536524409c0dd51bb7 /app/models/analytics | |
parent | 75c2755b05acdd65b5c7f93ee245b8273d99d446 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/analytics')
-rw-r--r-- | app/models/analytics/cycle_analytics/aggregation.rb | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/app/models/analytics/cycle_analytics/aggregation.rb b/app/models/analytics/cycle_analytics/aggregation.rb index b2705f84382..22a816d9f44 100644 --- a/app/models/analytics/cycle_analytics/aggregation.rb +++ b/app/models/analytics/cycle_analytics/aggregation.rb @@ -1,8 +1,14 @@ # frozen_string_literal: true + class Analytics::CycleAnalytics::Aggregation < ApplicationRecord + include FromUnion + belongs_to :group, optional: false - validates :incremental_runtimes_in_seconds, :incremental_processed_records, :last_full_run_runtimes_in_seconds, :last_full_run_processed_records, presence: true, length: { maximum: 10 } + validates :incremental_runtimes_in_seconds, :incremental_processed_records, :last_full_run_runtimes_in_seconds, :last_full_run_processed_records, presence: true, length: { maximum: 10 }, allow_blank: true + + scope :priority_order, -> { order('last_incremental_run_at ASC NULLS FIRST') } + scope :enabled, -> { where('enabled IS TRUE') } def self.safe_create_for_group(group) top_level_group = group.root_ancestor @@ -10,4 +16,22 @@ class Analytics::CycleAnalytics::Aggregation < ApplicationRecord insert({ group_id: top_level_group.id }, unique_by: :group_id) end + + def self.load_batch(last_run_at, batch_size = 100) + last_run_at_not_set = Analytics::CycleAnalytics::Aggregation + .enabled + .where(last_incremental_run_at: nil) + .priority_order + .limit(batch_size) + + last_run_at_before = Analytics::CycleAnalytics::Aggregation + .enabled + .where('last_incremental_run_at < ?', last_run_at) + .priority_order + .limit(batch_size) + + Analytics::CycleAnalytics::Aggregation + .from_union([last_run_at_not_set, last_run_at_before], remove_order: false, remove_duplicates: false) + .limit(batch_size) + end end |