@@ -3,28 +3,32 @@ class CleanupVotesJob < ApplicationJob
33
44 def perform
55 Community . all . each do |c |
6- RequestContext . community = c
7- orphan_votes = Vote . all . reject { |v | v . post . present? }
6+ logger . tagged ( c . name ) do
7+ RequestContext . community = c
8+ orphan_votes = Vote . all . reject { |v | v . post . present? }
89
9- puts "[ #{ c . name } ] destroying #{ orphan_votes . length } #{ 'orphan vote' . pluralize ( orphan_votes . length ) } "
10+ logger . info "Removing #{ orphan_votes . length } #{ 'orphan vote' . pluralize ( orphan_votes . length ) } "
1011
11- system_user = User . find ( -1 )
12+ system_user = User . find ( -1 )
1213
13- orphan_votes . each do |v |
14- result = v . destroy
14+ orphan_votes . each do |v |
15+ result = v . destroy
1516
16- if result
17- AuditLog . admin_audit (
18- comment : "Deleted orphaned vote for user ##{ v . recv_user_id } " \
19- "on post ##{ v . post_id } " \
20- "in community ##{ c . id } (#{ c . name } )" ,
21- event_type : 'vote_delete' ,
22- related : v ,
23- user : system_user
24- )
25- else
26- puts "[#{ c . name } ] failed to destroy vote \" #{ v . id } \" "
27- v . errors . each { |e | puts e . full_message }
17+ if result
18+ AuditLog . admin_audit (
19+ comment : "Deleted orphaned vote for user ##{ v . recv_user_id } " \
20+ "on post ##{ v . post_id } " \
21+ "in community ##{ c . id } (#{ c . name } )" ,
22+ event_type : 'vote_delete' ,
23+ related : v ,
24+ user : system_user
25+ )
26+ else
27+ logger . warn "Failed to remove vote #{ v . id } . Validations follow."
28+ v . errors . full_messages . each do |msg |
29+ logger . warn msg
30+ end
31+ end
2832 end
2933 end
3034 end
0 commit comments