Merge commit '25c66fa640
' into kb_migration
This commit is contained in:
commit
1f64358afb
107 changed files with 2159 additions and 1540 deletions
|
@ -23,23 +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.emoji_reactions = status.generate_emoji_reactions_grouped_by_name
|
||||
|
||||
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)
|
||||
|
@ -49,5 +38,36 @@ 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.emoji_reactions = status.generate_emoji_reactions_grouped_by_name
|
||||
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue