3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'app/jobs/rails_audit_log/write_audit_log_job.rb', line 3
def perform(entry_attrs, version_limit: nil)
AuditLogEntry.create!(entry_attrs)
return unless version_limit
item_type = entry_attrs["item_type"]
item_id = entry_attrs["item_id"]
count = AuditLogEntry.where(item_type: item_type, item_id: item_id).count
excess = count - version_limit
return unless excess > 0
AuditLogEntry.where(item_type: item_type, item_id: item_id)
.order(id: :asc)
.limit(excess)
.delete_all
end
|