Skip to content

Commit

Permalink
Address some of the review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire committed Oct 23, 2023
1 parent 99ce22a commit e8f902f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app/helpers/self_destruct_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

module SelfDestructHelper
def self.self_destruct?
ENV.fetch('SELF_DESTRUCT', nil).present? && Rails.application.message_verifier('self-destruct').verify(ENV.fetch('SELF_DESTRUCT', nil)) == ENV['LOCAL_DOMAIN']
value = ENV.fetch('SELF_DESTRUCT', nil)
value.present? && Rails.application.message_verifier('self-destruct').verify(value) == ENV['LOCAL_DOMAIN']
rescue ActiveSupport::MessageVerifier::InvalidSignature
false
end
Expand Down
11 changes: 11 additions & 0 deletions app/workers/scheduler/self_destruct_scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,23 @@ def sidekiq_overwhelmed?
end

def delete_accounts!
# We currently do not distinguish between deleted accounts and suspended
# accounts, and we do not want to remove the records in this scheduler, as
# we still rely on it for account delivery and don't want to perform
# needless work when the database can be outright dropped after the
# self-destruct.
# Deleted accounts are suspended accounts that do not have a pending
# deletion request.

# This targets accounts that have not been deleted nor marked for deletion yet
Account.local.without_suspended.reorder(id: :asc).take(MAX_ACCOUNT_DELETIONS_PER_JOB).each do |account|
delete_account!(account)
end

return if sidekiq_overwhelmed?

# This targets accounts that have been marked for deletion but have not been
# deleted yet
Account.local.suspended.joins(:deletion_request).take(MAX_ACCOUNT_DELETIONS_PER_JOB).each do |account|
delete_account!(account)
account.deletion_request&.destroy
Expand Down
2 changes: 1 addition & 1 deletion lib/mastodon/cli/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def self_destruct
exit(1) if prompt.no?('Are you sure you want to proceed?')

self_destruct_value = Rails.application.message_verifier('self-destruct').generate(Rails.configuration.x.local_domain)
prompt.ok('To switch Mastodon to self-destruct mode, add the following line to your `.env.production` and restart all Mastodon processes:')
prompt.ok('To switch Mastodon to self-destruct mode, add the following variable to your evironment (e.g. by adding a line to your `.env.production`) and restart all Mastodon processes:')
prompt.ok(" SELF_DESTRUCT=#{self_destruct_value}")
prompt.ok("\nYou can re-run this command to see the state of the self-destruct process.")
rescue TTY::Reader::InputInterrupt
Expand Down

0 comments on commit e8f902f

Please sign in to comment.