Skip to content

Commit

Permalink
Remove redundant temporary index creation in tootctl status remove (m…
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire authored Nov 22, 2024
1 parent 35683ac commit 9d34146
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 deletions lib/mastodon/cli/statuses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,11 @@ def remove
def remove_statuses
return if options[:skip_status_remove]

say('Creating temporary database indices...')

ActiveRecord::Base.connection.add_index(:media_attachments, :remote_url, name: :index_media_attachments_remote_url, where: 'remote_url is not null', algorithm: :concurrently, if_not_exists: true)
start_at = Time.now.to_f

max_id = Mastodon::Snowflake.id_at(options[:days].days.ago, with_random: false)
start_at = Time.now.to_f

unless options[:continue] && ActiveRecord::Base.connection.table_exists?('statuses_to_be_deleted')
ActiveRecord::Base.connection.add_index(:accounts, :id, name: :index_accounts_local, where: 'domain is null', algorithm: :concurrently, if_not_exists: true)
ActiveRecord::Base.connection.add_index(:status_pins, :status_id, name: :index_status_pins_status_id, algorithm: :concurrently, if_not_exists: true)

say('Extract the deletion target from statuses... This might take a while...')

ActiveRecord::Base.connection.create_table('statuses_to_be_deleted', force: true)
Expand All @@ -72,9 +66,6 @@ def remove_statuses
SQL

say('Removing temporary database indices to restore write performance...')

ActiveRecord::Base.connection.remove_index(:accounts, name: :index_accounts_local, if_exists: true)
ActiveRecord::Base.connection.remove_index(:status_pins, name: :index_status_pins_status_id, if_exists: true)
end

say('Beginning statuses removal... This might take a while...')
Expand Down Expand Up @@ -102,12 +93,6 @@ def remove_statuses
ActiveRecord::Base.connection.drop_table('statuses_to_be_deleted')

say("Done after #{Time.now.to_f - start_at}s, removed #{removed} out of #{processed} statuses.", :green)
ensure
say('Removing temporary database indices to restore write performance...')

ActiveRecord::Base.connection.remove_index(:accounts, name: :index_accounts_local, if_exists: true)
ActiveRecord::Base.connection.remove_index(:status_pins, name: :index_status_pins_status_id, if_exists: true)
ActiveRecord::Base.connection.remove_index(:media_attachments, name: :index_media_attachments_remote_url, if_exists: true)
end

def remove_orphans_media_attachments
Expand Down

0 comments on commit 9d34146

Please sign in to comment.