Commit 9c8210cc7f7dce683bc21571a9bcded89e512e3a
1 parent
f5671345
Exists in
master
and in
1 other branch
Adding task to invalidate bad response times
Showing
1 changed file
with
36 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,36 @@ |
1 | +namespace :prune_db do | |
2 | + | |
3 | + task :all => [:invalidate_votes_with_bad_response_times] | |
4 | + | |
5 | + task(:invalidate_votes_with_bad_response_times => :environment) do | |
6 | + badvotes = [] | |
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| | |
9 | + server_response_time = v.created_at.to_f - v.appearance.created_at.to_f | |
10 | + if v.time_viewed && v.time_viewed/1000 > server_response_time | |
11 | + badvotes << v | |
12 | + puts "." | |
13 | + end | |
14 | + end | |
15 | + puts "\n" | |
16 | + | |
17 | + if badvotes.any? | |
18 | + puts "You are about to change #{badvotes.size} votes. Are you sure you want to proceed? (y/N)" | |
19 | + choice = $stdin.gets | |
20 | + | |
21 | + unless choice.chomp.downcase == "y" | |
22 | + return | |
23 | + end | |
24 | + | |
25 | + badvotes.each do |v| | |
26 | + v.time_viewed = nil | |
27 | + v.missing_response_time_exp = "invalid" | |
28 | + v.save! | |
29 | + end | |
30 | + else | |
31 | + puts "Could not find any bad votes. Yay." | |
32 | + end | |
33 | + | |
34 | + end | |
35 | + | |
36 | +end | ... | ... |