Skip to content

Commit

Permalink
added audit log for when the cleanup_votes job successfully deletes o…
Browse files Browse the repository at this point in the history
…rphaned votes
  • Loading branch information
Oaphi committed Dec 18, 2024
1 parent 646db76 commit c1cbe8f
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions app/jobs/cleanup_votes_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,27 @@ def perform
Community.all.each do |c|
RequestContext.community = c
orphan_votes = Vote.all.reject { |v| v.post.present? }

puts "[#{c.name}] destroying #{orphan_votes.length} #{'orphan vote'.pluralize(orphan_votes.length)}"
failed = orphan_votes.reject(&:destroy)

failed.each do |v|
puts "[#{c.name}] failed to destroy vote \"#{v.id}\""
v.errors.each { |e| puts e.full_message }
system_user = User.find(-1)

orphan_votes.each do |v|
result = v.destroy

if result
AuditLog.admin_audit(
comment: "Deleted orphaned vote for user ##{v.recv_user_id} " \
"on post ##{v.post_id} " \
"in community ##{c.id} (#{c.name})",
event_type: 'vote_delete',
related: v,
user: system_user
)
else
puts "[#{c.name}] failed to destroy vote \"#{v.id}\""
v.errors.each { |e| puts e.full_message }
end
end
end
end
Expand Down

0 comments on commit c1cbe8f

Please sign in to comment.