From 9c8210cc7f7dce683bc21571a9bcded89e512e3a Mon Sep 17 00:00:00 2001 From: Dhruv Kapadia Date: Fri, 2 Jul 2010 11:38:52 -0400 Subject: [PATCH] Adding task to invalidate bad response times --- lib/tasks/prune_db.rake | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+), 0 deletions(-) create mode 100644 lib/tasks/prune_db.rake diff --git a/lib/tasks/prune_db.rake b/lib/tasks/prune_db.rake new file mode 100644 index 0000000..b19b484 --- /dev/null +++ b/lib/tasks/prune_db.rake @@ -0,0 +1,36 @@ +namespace :prune_db do + + task :all => [:invalidate_votes_with_bad_response_times] + + task(:invalidate_votes_with_bad_response_times => :environment) do + badvotes = [] + #might want to optimize later to not start from the beginning each time + Vote.find_each(:batch_size => 1000, :include => :appearance) do |v| + server_response_time = v.created_at.to_f - v.appearance.created_at.to_f + if v.time_viewed && v.time_viewed/1000 > server_response_time + badvotes << v + puts "." + end + end + puts "\n" + + if badvotes.any? + puts "You are about to change #{badvotes.size} votes. Are you sure you want to proceed? (y/N)" + choice = $stdin.gets + + unless choice.chomp.downcase == "y" + return + end + + badvotes.each do |v| + v.time_viewed = nil + v.missing_response_time_exp = "invalid" + v.save! + end + else + puts "Could not find any bad votes. Yay." + end + + end + +end -- libgit2 0.21.2