Commit ee6ef694541baa53957df3f94c402cecca01c3dd
1 parent
51357fdd
Exists in
master
and in
1 other branch
update invalidate_votes_with_bad_response_times
* do batches of 10000 * print instead of puts * remove confirmation since we'll be running this weekly from cron
Showing
1 changed file
with
3 additions
and
8 deletions
Show diff stats
lib/tasks/prune_db.rake
@@ -5,23 +5,18 @@ namespace :prune_db do | @@ -5,23 +5,18 @@ namespace :prune_db do | ||
5 | task(:invalidate_votes_with_bad_response_times => :environment) do | 5 | task(:invalidate_votes_with_bad_response_times => :environment) do |
6 | badvotes = [] | 6 | badvotes = [] |
7 | #might want to optimize later to not start from the beginning each time | 7 | #might want to optimize later to not start from the beginning each time |
8 | - Vote.find_each(:batch_size => 1000, :include => :appearance) do |v| | 8 | + STDOUT.sync = true |
9 | + Vote.find_each(:batch_size => 10000, :include => :appearance) do |v| | ||
9 | next if v.nil? || v.appearance.nil? | 10 | next if v.nil? || v.appearance.nil? |
10 | server_response_time = v.created_at.to_f - v.appearance.created_at.to_f | 11 | server_response_time = v.created_at.to_f - v.appearance.created_at.to_f |
11 | if v.time_viewed && v.time_viewed/1000 > server_response_time | 12 | if v.time_viewed && v.time_viewed/1000 > server_response_time |
12 | badvotes << v | 13 | badvotes << v |
13 | - puts "." | 14 | + print "." |
14 | end | 15 | end |
15 | end | 16 | end |
16 | puts "\n" | 17 | puts "\n" |
17 | 18 | ||
18 | if badvotes.any? | 19 | if badvotes.any? |
19 | - puts "You are about to change #{badvotes.size} votes. Are you sure you want to proceed? (y/N)" | ||
20 | - choice = $stdin.gets | ||
21 | - | ||
22 | - unless choice.chomp.downcase == "y" | ||
23 | - return | ||
24 | - end | ||
25 | 20 | ||
26 | badvotes.each do |v| | 21 | badvotes.each do |v| |
27 | v.time_viewed = nil | 22 | v.time_viewed = nil |