Merge commit '39110d1d0af5e3d9cf452ae47496a52797249fd0' into glitch-soc/merge-upstream
This commit is contained in:
@ -23,22 +23,12 @@ module Mastodon::CLI
|
||||
def recount(type)
|
||||
case type
|
||||
when 'accounts'
|
||||
processed, = parallelize_with_progress(Account.local.includes(:account_stat)) do |account|
|
||||
account_stat = account.account_stat
|
||||
account_stat.following_count = account.active_relationships.count
|
||||
account_stat.followers_count = account.passive_relationships.count
|
||||
account_stat.statuses_count = account.statuses.where.not(visibility: :direct).count
|
||||
|
||||
account_stat.save if account_stat.changed?
|
||||
processed, = parallelize_with_progress(accounts_with_stats) do |account|
|
||||
recount_account_stats(account)
|
||||
end
|
||||
when 'statuses'
|
||||
processed, = parallelize_with_progress(Status.includes(:status_stat)) do |status|
|
||||
status_stat = status.status_stat
|
||||
status_stat.replies_count = status.replies.where.not(visibility: :direct).count
|
||||
status_stat.reblogs_count = status.reblogs.count
|
||||
status_stat.favourites_count = status.favourites.count
|
||||
|
||||
status_stat.save if status_stat.changed?
|
||||
processed, = parallelize_with_progress(statuses_with_stats) do |status|
|
||||
recount_status_stats(status)
|
||||
end
|
||||
else
|
||||
say("Unknown type: #{type}", :red)
|
||||
@ -48,5 +38,35 @@ module Mastodon::CLI
|
||||
say
|
||||
say("OK, recounted #{processed} records", :green)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def accounts_with_stats
|
||||
Account.local.includes(:account_stat)
|
||||
end
|
||||
|
||||
def statuses_with_stats
|
||||
Status.includes(:status_stat)
|
||||
end
|
||||
|
||||
def recount_account_stats(account)
|
||||
account.account_stat.tap do |account_stat|
|
||||
account_stat.following_count = account.active_relationships.count
|
||||
account_stat.followers_count = account.passive_relationships.count
|
||||
account_stat.statuses_count = account.statuses.where.not(visibility: :direct).count
|
||||
|
||||
account_stat.save if account_stat.changed?
|
||||
end
|
||||
end
|
||||
|
||||
def recount_status_stats(status)
|
||||
status.status_stat.tap do |status_stat|
|
||||
status_stat.replies_count = status.replies.where.not(visibility: :direct).count
|
||||
status_stat.reblogs_count = status.reblogs.count
|
||||
status_stat.favourites_count = status.favourites.count
|
||||
|
||||
status_stat.save if status_stat.changed?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -19,7 +19,7 @@ module Mastodon::CLI
|
||||
LONG_DESC
|
||||
def build(username = nil)
|
||||
if options[:all] || username.nil?
|
||||
processed, = parallelize_with_progress(Account.joins(:user).merge(User.active)) do |account|
|
||||
processed, = parallelize_with_progress(active_user_accounts) do |account|
|
||||
PrecomputeFeedService.new.call(account) unless dry_run?
|
||||
end
|
||||
|
||||
@ -47,5 +47,11 @@ module Mastodon::CLI
|
||||
redis.del(keys)
|
||||
say('OK', :green)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def active_user_accounts
|
||||
Account.joins(:user).merge(User.active)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user