summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2023-08-10 13:13:59 +0200
committerClaire <claire.github-309c@sitedethib.com>2023-08-10 16:59:38 +0200
commitd7a42ae7165f1b2029d655c102132ccbb9c204e5 (patch)
treefcd3a6fed795457d16673ab83cddae6ed5ade4b1
parentef2a6bc6469e875fc29a0f0ec381b78f3858cf8f (diff)
Throttle account deletions in `tootctl self-destruct` to avoid overwhelming Sidekiq/Redisfixes/self-destruct-throttle
-rw-r--r--lib/mastodon/cli/main.rb27
1 files changed, 25 insertions, 2 deletions
diff --git a/lib/mastodon/cli/main.rb b/lib/mastodon/cli/main.rb
index 4fa3e371cea..402aca6307e 100644
--- a/lib/mastodon/cli/main.rb
+++ b/lib/mastodon/cli/main.rb
@@ -20,6 +20,8 @@ require_relative 'upgrade'
module Mastodon::CLI
class Main < Base
+ include Redisable
+
desc 'media SUBCOMMAND ...ARGS', 'Manage media files'
subcommand 'media', Media
@@ -137,8 +139,21 @@ module Mastodon::CLI
processed += 1
end
- Account.local.without_suspended.find_each { |account| delete_account.call(account) }
- Account.local.suspended.joins(:deletion_request).find_each { |account| delete_account.call(account) }
+ Account.local.without_suspended.find_in_batches(batch_size: 50) do |accounts|
+ accounts.each { |account| delete_account.call(account) }
+
+ prompt.ok("Processed accounts so far: #{processed}")
+
+ sleep 5 while sidekiq_overwhelmed?
+ end
+
+ Account.local.suspended.joins(:deletion_request).find_in_batches(batch_size: 50) do |accounts|
+ accounts.each { |account| delete_account.call(account) }
+
+ prompt.ok("Processed accounts so far: #{processed}")
+
+ sleep 5 while sidekiq_overwhelmed?
+ end
prompt.ok("Queued #{inboxes.size * processed} items into Sidekiq for #{processed} accounts#{dry_run_mode_suffix}")
prompt.ok('Wait until Sidekiq processes all items, then you can shut everything down and delete the data')
@@ -152,5 +167,13 @@ module Mastodon::CLI
def version
say(Mastodon::Version.to_s)
end
+
+ private
+
+ def sidekiq_overwhelmed?
+ redis_mem_info = Sidekiq.redis_info
+
+ Sidekiq::Stats.new.enqueued > 5000 || redis_mem_info['used_memory'].to_f * 2 > redis_mem_info['total_system_memory'].to_f
+ end
end
end