diff options
Diffstat (limited to 'app/models/audit_event.rb')
-rw-r--r-- | app/models/audit_event.rb | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/app/models/audit_event.rb b/app/models/audit_event.rb index f46803be057..34f03e769a0 100644 --- a/app/models/audit_event.rb +++ b/app/models/audit_event.rb @@ -4,8 +4,15 @@ class AuditEvent < ApplicationRecord include CreatedAtFilterable include IgnorableColumns include BulkInsertSafe + include EachBatch - PARALLEL_PERSISTENCE_COLUMNS = [:author_name, :entity_path, :target_details, :target_type].freeze + PARALLEL_PERSISTENCE_COLUMNS = [ + :author_name, + :entity_path, + :target_details, + :target_type, + :target_id + ].freeze ignore_column :type, remove_with: '13.6', remove_after: '2020-11-22' @@ -16,6 +23,7 @@ class AuditEvent < ApplicationRecord validates :author_id, presence: true validates :entity_id, presence: true validates :entity_type, presence: true + validates :ip_address, ip_address: true scope :by_entity_type, -> (entity_type) { where(entity_type: entity_type) } scope :by_entity_id, -> (entity_id) { where(entity_id: entity_id) } @@ -47,7 +55,9 @@ class AuditEvent < ApplicationRecord end def initialize_details - self.details = {} if details.nil? + return unless self.has_attribute?(:details) + + self.details = {} if details&.nil? end def author_name @@ -59,8 +69,8 @@ class AuditEvent < ApplicationRecord end def lazy_author - BatchLoader.for(author_id).batch(default_value: default_author_value) do |author_ids, loader| - User.where(id: author_ids).find_each do |user| + BatchLoader.for(author_id).batch(default_value: default_author_value, replace_methods: false) do |author_ids, loader| + User.select(:id, :name, :username).where(id: author_ids).find_each do |user| loader.call(user.id, user) end end |