Class: MergeRequest::Metrics

Inherits:
ApplicationRecord show all
Defined in:
app/models/merge_request/metrics.rb

Constant Summary

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from HasCheckConstraints

HasCheckConstraints::NOT_NULL_CHECK_PATTERN

Constants included from ResetOnColumnErrors

ResetOnColumnErrors::MAX_RESET_PERIOD

Class Method Summary collapse

Methods inherited from ApplicationRecord

===, cached_column_list, #create_or_load_association, current_transaction, declarative_enum, default_select_columns, delete_all_returning, #deleted_from_database?, id_in, id_not_in, iid_in, nullable_column?, 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 Organizations::Sharding

#sharding_organization

Methods included from ResetOnColumnErrors

#reset_on_union_error, #reset_on_unknown_attribute_error

Methods included from Gitlab::SensitiveSerializableHash

#serializable_hash

Class Method Details

.record!(mr) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/models/merge_request/metrics.rb', line 25

def record!(mr)
  inserted_columns = i[merge_request_id target_project_id updated_at created_at]
  sql = "    INSERT INTO \#{self.table_name} (\#{inserted_columns.join(', ')})\n    VALUES (\#{mr.id}, \#{mr.target_project_id}, NOW(), NOW())\n    ON CONFLICT (merge_request_id)\n    DO UPDATE SET\n    target_project_id = EXCLUDED.target_project_id,\n    updated_at = NOW()\n    RETURNING id, \#{inserted_columns.join(', ')}\n  SQL\n\n  connection.execute(sql)\nend\n"

.time_to_merge_expressionObject



21
22
23
# File 'app/models/merge_request/metrics.rb', line 21

def time_to_merge_expression
  Arel.sql('EXTRACT(epoch FROM SUM(AGE(merge_request_metrics.merged_at, merge_request_metrics.created_at)))')
end

.total_time_to_mergeObject



47
48
49
50
# File 'app/models/merge_request/metrics.rb', line 47

def self.total_time_to_merge
  with_valid_time_to_merge
    .pick(time_to_merge_expression)
end