justask;recount now recounts the smile_counts too.
This commit is contained in:
parent
027f2629b1
commit
c7221ef377
17
Rakefile
17
Rakefile
|
@ -6,24 +6,37 @@ require File.expand_path('../config/application', __FILE__)
|
||||||
Rails.application.load_tasks
|
Rails.application.load_tasks
|
||||||
|
|
||||||
namespace :justask do
|
namespace :justask do
|
||||||
desc "Recount every user's answer/question count."
|
desc "Recount everything!"
|
||||||
task recount: :environment do
|
task recount: :environment do
|
||||||
|
format = '%t (%c/%C) [%b>%i] %e'
|
||||||
total = User.count
|
total = User.count
|
||||||
progress = ProgressBar.create title: 'Processing user', format: "%t (%c/%C) [%b>%i] %e", starting_at: 0, total: total
|
progress = ProgressBar.create title: 'Processing users', format: format, starting_at: 0, total: total
|
||||||
User.all.each do |user|
|
User.all.each do |user|
|
||||||
begin
|
begin
|
||||||
answered = Answer.where(user: user).count
|
answered = Answer.where(user: user).count
|
||||||
asked = Question.where(user: user).where(author_is_anonymous: false).count
|
asked = Question.where(user: user).where(author_is_anonymous: false).count
|
||||||
commented = Comment.where(user: user).count
|
commented = Comment.where(user: user).count
|
||||||
|
smiled = Smile.where(user: user).count
|
||||||
user.friend_count = user.friends.count
|
user.friend_count = user.friends.count
|
||||||
user.follower_count = user.followers.count
|
user.follower_count = user.followers.count
|
||||||
user.answered_count = answered
|
user.answered_count = answered
|
||||||
user.asked_count = asked
|
user.asked_count = asked
|
||||||
user.commented_count = commented
|
user.commented_count = commented
|
||||||
|
user.smiled_count = smiled
|
||||||
user.save!
|
user.save!
|
||||||
end
|
end
|
||||||
progress.increment
|
progress.increment
|
||||||
end
|
end
|
||||||
|
total = Answer.count
|
||||||
|
progress = ProgressBar.create title: 'Processing answers', format: format, starting_at: 0, total: total
|
||||||
|
Answer.all.each do |answer|
|
||||||
|
begin
|
||||||
|
smiles = Smile.where(answer: answer).count
|
||||||
|
answer.smile_count = smiles
|
||||||
|
answer.save!
|
||||||
|
end
|
||||||
|
progress.increment
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "Gives admin status to an user."
|
desc "Gives admin status to an user."
|
||||||
|
|
Loading…
Reference in New Issue