Skip to content

Commit

Permalink
Extract rebuild_index method in maintenance CLI (mastodon#28911)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjankowski authored Jan 25, 2024
1 parent 0b38946 commit 4cdf62e
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/mastodon/cli/maintenance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,10 @@ def deduplicate_accounts!
end

say 'Reindexing textual indexes on accounts…'
database_connection.execute('REINDEX INDEX search_index;')
database_connection.execute('REINDEX INDEX index_accounts_on_uri;')
database_connection.execute('REINDEX INDEX index_accounts_on_url;')
database_connection.execute('REINDEX INDEX index_accounts_on_domain_and_id;') if migrator_version >= 2023_05_24_190515
rebuild_index(:search_index)
rebuild_index(:index_accounts_on_uri)
rebuild_index(:index_accounts_on_url)
rebuild_index(:index_accounts_on_domain_and_id) if migrator_version >= 2023_05_24_190515
end

def deduplicate_users!
Expand All @@ -274,7 +274,7 @@ def deduplicate_users!
database_connection.add_index :users, ['reset_password_token'], name: 'index_users_on_reset_password_token', unique: true, where: 'reset_password_token IS NOT NULL', opclass: :text_pattern_ops
end

database_connection.execute('REINDEX INDEX index_users_on_unconfirmed_email;') if migrator_version >= 2023_07_02_151753
rebuild_index(:index_users_on_unconfirmed_email) if migrator_version >= 2023_07_02_151753
end

def deduplicate_users_process_email
Expand Down Expand Up @@ -735,5 +735,9 @@ def database_connection
def db_table_exists?(table)
database_connection.table_exists?(table)
end

def rebuild_index(name)
database_connection.execute("REINDEX INDEX #{name}")
end
end
end

0 comments on commit 4cdf62e

Please sign in to comment.