Change tootctl to use inline parallelization instead of Sidekiq (#11776)
- Remove --background option - Add --concurrency(=5) option - Add progress bars
This commit is contained in:
parent
9045f5e3f8
commit
8674814825
15 changed files with 200 additions and 337 deletions
|
@ -6,6 +6,8 @@ require_relative 'cli_helper'
|
|||
|
||||
module Mastodon
|
||||
class CacheCLI < Thor
|
||||
include CLIHelper
|
||||
|
||||
def self.exit_on_failure?
|
||||
true
|
||||
end
|
||||
|
@ -16,6 +18,8 @@ module Mastodon
|
|||
say('OK', :green)
|
||||
end
|
||||
|
||||
option :concurrency, type: :numeric, default: 5, aliases: [:c]
|
||||
option :verbose, type: :boolean, aliases: [:v]
|
||||
desc 'recount TYPE', 'Update hard-cached counters'
|
||||
long_desc <<~LONG_DESC
|
||||
Update hard-cached counters of TYPE by counting referenced
|
||||
|
@ -25,32 +29,24 @@ module Mastodon
|
|||
size of the database.
|
||||
LONG_DESC
|
||||
def recount(type)
|
||||
processed = 0
|
||||
|
||||
case type
|
||||
when 'accounts'
|
||||
Account.local.includes(:account_stat).find_each do |account|
|
||||
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 += 1
|
||||
say('.', :green, false)
|
||||
end
|
||||
when 'statuses'
|
||||
Status.includes(:status_stat).find_each do |status|
|
||||
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 += 1
|
||||
say('.', :green, false)
|
||||
end
|
||||
else
|
||||
say("Unknown type: #{type}", :red)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue