diff options
Diffstat (limited to 'app/models/analytics/cycle_analytics')
-rw-r--r-- | app/models/analytics/cycle_analytics/aggregation.rb | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/app/models/analytics/cycle_analytics/aggregation.rb b/app/models/analytics/cycle_analytics/aggregation.rb index 44d2dc369f7..2c04e67a04b 100644 --- a/app/models/analytics/cycle_analytics/aggregation.rb +++ b/app/models/analytics/cycle_analytics/aggregation.rb @@ -1,15 +1,53 @@ # frozen_string_literal: true class Analytics::CycleAnalytics::Aggregation < ApplicationRecord + include IgnorableColumns 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 }, allow_blank: true + validates :incremental_runtimes_in_seconds, :incremental_processed_records, :full_runtimes_in_seconds, :full_processed_records, presence: true, length: { maximum: 10 }, allow_blank: true scope :priority_order, -> (column_to_sort = :last_incremental_run_at) { order(arel_table[column_to_sort].asc.nulls_first) } scope :enabled, -> { where('enabled IS TRUE') } + # These columns were added with wrong naming convention, the columns were never used. + ignore_column :last_full_run_processed_records, remove_with: '15.1', remove_after: '2022-05-22' + ignore_column :last_full_run_runtimes_in_seconds, remove_with: '15.1', remove_after: '2022-05-22' + ignore_column :last_full_run_issues_updated_at, remove_with: '15.1', remove_after: '2022-05-22' + ignore_column :last_full_run_mrs_updated_at, remove_with: '15.1', remove_after: '2022-05-22' + ignore_column :last_full_run_issues_id, remove_with: '15.1', remove_after: '2022-05-22' + ignore_column :last_full_run_merge_requests_id, remove_with: '15.1', remove_after: '2022-05-22' + + def cursor_for(mode, model) + { + updated_at: self["last_#{mode}_#{model.table_name}_updated_at"], + id: self["last_#{mode}_#{model.table_name}_id"] + }.compact + end + + def refresh_last_run(mode) + self["last_#{mode}_run_at"] = Time.current + end + + def reset_full_run_cursors + self.last_full_issues_id = nil + self.last_full_issues_updated_at = nil + self.last_full_merge_requests_id = nil + self.last_full_merge_requests_updated_at = nil + end + + def set_cursor(mode, model, cursor) + self["last_#{mode}_#{model.table_name}_id"] = cursor[:id] + self["last_#{mode}_#{model.table_name}_updated_at"] = cursor[:updated_at] + end + + def set_stats(mode, runtime, processed_records) + # We only store the last 10 data points + self["#{mode}_runtimes_in_seconds"] = (self["#{mode}_runtimes_in_seconds"] + [runtime]).last(10) + self["#{mode}_processed_records"] = (self["#{mode}_processed_records"] + [processed_records]).last(10) + end + def estimated_next_run_at return unless enabled return if last_incremental_run_at.nil? |