Class: MergeRequest::Metrics
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- MergeRequest::Metrics
- Defined in:
- app/models/merge_request/metrics.rb
Constant Summary
Constants inherited from ApplicationRecord
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
Methods included from ResetOnColumnErrors
#reset_on_union_error, #reset_on_unknown_attribute_error
Methods included from Gitlab::SensitiveSerializableHash
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 = <<~SQL INSERT INTO #{self.table_name} (#{inserted_columns.join(', ')}) VALUES (#{mr.id}, #{mr.target_project_id}, NOW(), NOW()) ON CONFLICT (merge_request_id) DO UPDATE SET target_project_id = EXCLUDED.target_project_id, updated_at = NOW() RETURNING id, #{inserted_columns.join(', ')} SQL connection.execute(sql) end |
.time_to_merge_expression ⇒ Object
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_merge ⇒ Object
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 |