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