diff options
author | Claire <claire.github-309c@sitedethib.com> | 2021-10-14 22:57:41 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-14 22:57:41 +0200 |
commit | b6f24ef0fb8b594c38c29090518c21af051b63b7 (patch) | |
tree | 5cec6a6b13dfd062848c74ae8e041c589ae40d00 /lib | |
parent | ebf2c3195615bb524f6908e84f99887c8775cbc3 (diff) | |
parent | 6964952d5f242ca936de9df361185b3e70a99ca4 (diff) |
Merge pull request #1622 from ClearlyClaire/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'lib')
-rw-r--r-- | lib/cli.rb | 22 | ||||
-rw-r--r-- | lib/mastodon/accounts_cli.rb | 11 |
2 files changed, 21 insertions, 12 deletions
diff --git a/lib/cli.rb b/lib/cli.rb index 3f1658566..8815e137a 100644 --- a/lib/cli.rb +++ b/lib/cli.rb @@ -94,17 +94,22 @@ module Mastodon exit(1) unless prompt.ask('Type in the domain of the server to confirm:', required: true) == Rails.configuration.x.local_domain - prompt.warn('This operation WILL NOT be reversible. It can also take a long time.') - prompt.warn('While the data won\'t be erased locally, the server will be in a BROKEN STATE afterwards.') - prompt.warn('A running Sidekiq process is required. Do not shut it down until queues clear.') + unless options[:dry_run] + prompt.warn('This operation WILL NOT be reversible. It can also take a long time.') + prompt.warn('While the data won\'t be erased locally, the server will be in a BROKEN STATE afterwards.') + prompt.warn('A running Sidekiq process is required. Do not shut it down until queues clear.') - exit(1) if prompt.no?('Are you sure you want to proceed?') + exit(1) if prompt.no?('Are you sure you want to proceed?') + end inboxes = Account.inboxes processed = 0 dry_run = options[:dry_run] ? ' (DRY RUN)' : '' + Setting.registrations_mode = 'none' unless options[:dry_run] + if inboxes.empty? + Account.local.without_suspended.in_batches.update_all(suspended_at: Time.now.utc, suspension_origin: :local) unless options[:dry_run] prompt.ok('It seems like your server has not federated with anything') prompt.ok('You can shut it down and delete it any time') return @@ -112,9 +117,7 @@ module Mastodon prompt.warn('Do NOT interrupt this process...') - Setting.registrations_mode = 'none' - - Account.local.without_suspended.find_each do |account| + delete_account = ->(account) do payload = ActiveModelSerializers::SerializableResource.new( account, serializer: ActivityPub::DeleteActorSerializer, @@ -128,12 +131,15 @@ module Mastodon [json, account.id, inbox_url] end - account.suspend! + account.suspend!(block_email: false) end 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) } + prompt.ok("Queued #{inboxes.size * processed} items into Sidekiq for #{processed} accounts#{dry_run}") prompt.ok('Wait until Sidekiq processes all items, then you can shut everything down and delete the data') rescue TTY::Reader::InputInterrupt diff --git a/lib/mastodon/accounts_cli.rb b/lib/mastodon/accounts_cli.rb index 050194801..2ef85d0a9 100644 --- a/lib/mastodon/accounts_cli.rb +++ b/lib/mastodon/accounts_cli.rb @@ -287,7 +287,7 @@ module Mastodon option :concurrency, type: :numeric, default: 5, aliases: [:c] option :dry_run, type: :boolean - desc 'cull', 'Remove remote accounts that no longer exist' + desc 'cull [DOMAIN...]', 'Remove remote accounts that no longer exist' long_desc <<-LONG_DESC Query every single remote account in the database to determine if it still exists on the origin server, and if it doesn't, @@ -296,19 +296,22 @@ module Mastodon Accounts that have had confirmed activity within the last week are excluded from the checks. LONG_DESC - def cull + def cull(*domains) skip_threshold = 7.days.ago dry_run = options[:dry_run] ? ' (DRY RUN)' : '' skip_domains = Concurrent::Set.new - processed, culled = parallelize_with_progress(Account.remote.where(protocol: :activitypub).partitioned) do |account| + query = Account.remote.where(protocol: :activitypub) + query = query.where(domain: domains) unless domains.empty? + + processed, culled = parallelize_with_progress(query.partitioned) do |account| next if account.updated_at >= skip_threshold || (account.last_webfingered_at.present? && account.last_webfingered_at >= skip_threshold) || skip_domains.include?(account.domain) code = 0 begin code = Request.new(:head, account.uri).perform(&:code) - rescue HTTP::ConnectionError + rescue HTTP::TimeoutError, HTTP::ConnectionError, OpenSSL::SSL::SSLError skip_domains << account.domain end |