Class: ProjectDailyStatistic
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- ProjectDailyStatistic
- Includes:
- CounterAttribute, PartitionedTable
- Defined in:
- app/models/project_daily_statistic.rb
Constant Summary
Constants included from Gitlab::ExclusiveLeaseHelpers
Gitlab::ExclusiveLeaseHelpers::FailedToObtainLockError
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 included from CounterAttribute
#bulk_increment_counter, #counter, #counter_attribute_enabled?, #counters_key_prefix, #current_counter, #execute_after_commit_callbacks, #finalize_refresh, #increment_amount, #increment_counter, #initiate_refresh!, #update_counters, #update_counters_with_lease
Methods included from Gitlab::ExclusiveLeaseHelpers
Methods included from AfterCommitQueue
#run_after_commit, #run_after_commit_or_now
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
.find_or_create_project_daily_statistic(project_id, date) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/models/project_daily_statistic.rb', line 20 def self.find_or_create_project_daily_statistic(project_id, date) daily_statistic = find_by(project_id: project_id, date: date) return daily_statistic if daily_statistic result = upsert( { project_id: project_id, date: date, fetch_count: 0 }, unique_by: [:project_id, :date], on_duplicate: :skip ) statistic_id = result&.rows&.first&.first if statistic_id find_by_id(statistic_id) else find_by!(project_id: project_id, date: date) end end |