diff options
Diffstat (limited to 'app/models/audit_event.rb')
-rw-r--r-- | app/models/audit_event.rb | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/app/models/audit_event.rb b/app/models/audit_event.rb index 3bbd2e43a51..13fc2514f0c 100644 --- a/app/models/audit_event.rb +++ b/app/models/audit_event.rb @@ -3,8 +3,11 @@ class AuditEvent < ApplicationRecord include CreatedAtFilterable include IgnorableColumns + include BulkInsertSafe - ignore_column :updated_at, remove_with: '13.3', remove_after: '2020-08-22' + PARALLEL_PERSISTENCE_COLUMNS = [:author_name, :entity_path].freeze + + ignore_column :updated_at, remove_with: '13.4', remove_after: '2020-09-22' serialize :details, Hash # rubocop:disable Cop/ActiveRecordSerialize @@ -16,8 +19,15 @@ class AuditEvent < ApplicationRecord scope :by_entity_type, -> (entity_type) { where(entity_type: entity_type) } scope :by_entity_id, -> (entity_id) { where(entity_id: entity_id) } + scope :by_author_id, -> (author_id) { where(author_id: author_id) } after_initialize :initialize_details + # Note: The intention is to remove this once refactoring of AuditEvent + # has proceeded further. + # + # See further details in the epic: + # https://gitlab.com/groups/gitlab-org/-/epics/2765 + after_validation :parallel_persist def self.order_by(method) case method.to_s @@ -51,7 +61,11 @@ class AuditEvent < ApplicationRecord private def default_author_value - ::Gitlab::Audit::NullAuthor.for(author_id, details[:author_name]) + ::Gitlab::Audit::NullAuthor.for(author_id, (self[:author_name] || details[:author_name])) + end + + def parallel_persist + PARALLEL_PERSISTENCE_COLUMNS.each { |col| self[col] = details[col] } end end |