added justask:recount rake task

This commit is contained in:
nilsding 2014-11-28 22:02:32 +01:00
parent 5608148550
commit ccc1b47cb3
3 changed files with 25 additions and 0 deletions

View File

@ -29,6 +29,8 @@ gem 'nprogress-rails'
gem 'font-awesome-rails', '~> 4.2.0.0' gem 'font-awesome-rails', '~> 4.2.0.0'
gem 'rails-assets-growl' gem 'rails-assets-growl'
gem 'ruby-progressbar'
group :development do group :development do
gem 'spring' gem 'spring'
end end

View File

@ -151,6 +151,7 @@ GEM
rspec-mocks (~> 3.0.0) rspec-mocks (~> 3.0.0)
rspec-support (~> 3.0.0) rspec-support (~> 3.0.0)
rspec-support (3.0.4) rspec-support (3.0.4)
ruby-progressbar (1.5.1)
sass (3.2.19) sass (3.2.19)
sass-rails (4.0.5) sass-rails (4.0.5)
railties (>= 4.0.0, < 5.0) railties (>= 4.0.0, < 5.0)
@ -228,6 +229,7 @@ DEPENDENCIES
rails (= 4.1.7) rails (= 4.1.7)
rails-assets-growl rails-assets-growl
rspec-rails (~> 3.0.0) rspec-rails (~> 3.0.0)
ruby-progressbar
sass-rails (~> 4.0.3) sass-rails (~> 4.0.3)
sdoc (~> 0.4.1) sdoc (~> 0.4.1)
simplecov simplecov

View File

@ -4,3 +4,24 @@
require File.expand_path('../config/application', __FILE__) require File.expand_path('../config/application', __FILE__)
Rails.application.load_tasks Rails.application.load_tasks
namespace :justask do
desc "Recount every user's answer/question count."
task recount: :environment do
total = User.count
progress = ProgressBar.create title: 'Processing user', format: "%t (%c/%C) [%b>%i] %e", starting_at: 1, total: total
User.all do |user|
begin
answered = Question.where(user: user).count
asked = Question.where(user: user).where(author_is_anonymous: false).count
commented = Question.where(user: user).count
user.answered_count = answered
user.asked_count = asked
user.commented_count = commented
user.save!
end
progress.increment
end
puts
end
end