From 1f0cd07aa5ba02d00289afc081b87d982aa9ffc3 Mon Sep 17 00:00:00 2001 From: robcolbert Date: Wed, 3 Jul 2019 19:27:50 -0400 Subject: [PATCH] rake task to update user stats/counts --- lib/tasks/fix_account_stats.rake | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 lib/tasks/fix_account_stats.rake diff --git a/lib/tasks/fix_account_stats.rake b/lib/tasks/fix_account_stats.rake new file mode 100644 index 00000000..2b6e60e6 --- /dev/null +++ b/lib/tasks/fix_account_stats.rake @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +task fix_account_stats: 'gabsocial:fix-account-stats' + +namespace :gabsocial do + desc 'Re-compute user statistics (following cnt, followers cnt, etc.)' + task :fix_account_stats => :environment do + Account.select(:id, :username).all.each do |a| + a.account_stat.following_count = Follow.where(account_id: a.id).count + a.account_stat.followers_count = Follow.where(target_account_id: a.id).count + a.account_stat.statuses_count = Status.where(account_id: a.id).count + a.account_stat.save! + puts(a.username) + end + end +end