Class: Analytics::UsageTrends::Measurement

Inherits:
ApplicationRecord show all
Defined in:
app/models/analytics/usage_trends/measurement.rb

Constant Summary

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from ResetOnUnionError

ResetOnUnionError::MAX_RESET_PERIOD

Class Method Summary collapse

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from SensitiveSerializableHash

#serializable_hash

Class Method Details

.find_latest_or_fallback(identifier) ⇒ Object



54
55
56
# File 'app/models/analytics/usage_trends/measurement.rb', line 54

def self.find_latest_or_fallback(identifier)
  with_identifier(identifier).order_by_latest.first || identifier_query_mapping[identifiers[identifier]].call
end

.identifier_min_max_queriesObject

Customized min and max calculation, in some cases using the original scope is too slow.



46
47
48
# File 'app/models/analytics/usage_trends/measurement.rb', line 46

def self.identifier_min_max_queries
  {}
end

.identifier_query_mappingObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/models/analytics/usage_trends/measurement.rb', line 30

def self.identifier_query_mapping
  {
    identifiers[:projects] => -> { Project },
    identifiers[:users] => -> { User },
    identifiers[:issues] => -> { Issue },
    identifiers[:merge_requests] => -> { MergeRequest },
    identifiers[:groups] => -> { Group },
    identifiers[:pipelines] => -> { Ci::Pipeline },
    identifiers[:pipelines_succeeded] => -> { Ci::Pipeline.success },
    identifiers[:pipelines_failed] => -> { Ci::Pipeline.failed },
    identifiers[:pipelines_canceled] => -> { Ci::Pipeline.canceled },
    identifiers[:pipelines_skipped] => -> { Ci::Pipeline.skipped }
  }
end

.measurement_identifier_valuesObject



50
51
52
# File 'app/models/analytics/usage_trends/measurement.rb', line 50

def self.measurement_identifier_values
  identifiers.values
end