added justask:recount rake task
This commit is contained in:
parent
5608148550
commit
ccc1b47cb3
2
Gemfile
2
Gemfile
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
21
Rakefile
21
Rakefile
|
@ -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
|
Loading…
Reference in New Issue