diff --git a/Gemfile b/Gemfile index f6c7d5f4..f1c7ab2a 100644 --- a/Gemfile +++ b/Gemfile @@ -29,6 +29,8 @@ gem 'nprogress-rails' gem 'font-awesome-rails', '~> 4.2.0.0' gem 'rails-assets-growl' +gem 'ruby-progressbar' + group :development do gem 'spring' end diff --git a/Gemfile.lock b/Gemfile.lock index 5237c61b..c3427a57 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -151,6 +151,7 @@ GEM rspec-mocks (~> 3.0.0) rspec-support (~> 3.0.0) rspec-support (3.0.4) + ruby-progressbar (1.5.1) sass (3.2.19) sass-rails (4.0.5) railties (>= 4.0.0, < 5.0) @@ -228,6 +229,7 @@ DEPENDENCIES rails (= 4.1.7) rails-assets-growl rspec-rails (~> 3.0.0) + ruby-progressbar sass-rails (~> 4.0.3) sdoc (~> 0.4.1) simplecov diff --git a/Rakefile b/Rakefile index ba6b733d..dd550447 100644 --- a/Rakefile +++ b/Rakefile @@ -4,3 +4,24 @@ require File.expand_path('../config/application', __FILE__) 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 \ No newline at end of file