Skip to content

Commit

Permalink
added CleanupVotes daily job for removing orphaned votes
Browse files Browse the repository at this point in the history
  • Loading branch information
Oaphi committed Dec 16, 2024
1 parent c7499fa commit 646db76
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/jobs/cleanup_votes_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class CleanupVotesJob < ApplicationJob
queue_as :default

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 }
end
end
end
end
4 changes: 4 additions & 0 deletions config/schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
runner 'scripts/cleanup_drafts.rb'
end

every 1.day, ay: '02.25' do
runner 'scripts/cleanup_votes.rb'
end

every 6.hours do
runner 'scripts/recalc_abilities.rb'
end
1 change: 1 addition & 0 deletions scripts/cleanup_votes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CleanupVotesJob.perform_later

0 comments on commit 646db76

Please sign in to comment.