PERF: speed up user deletion logic

Previously any user deletion would scan a very large number of tables

This avoids scans on 6 tables/indexes on delete
This commit is contained in:
Sam Saffron
2019-04-26 18:11:39 +10:00
parent be0ae2e487
commit c009a6ae36
2 changed files with 19 additions and 1 deletions

View File

@@ -0,0 +1,10 @@
class AddMissingUserDestroyerIndexes < ActiveRecord::Migration[5.2]
def change
# these indexes are required to make deletions of users fast
add_index :user_actions, [:target_user_id], where: 'target_user_id IS NOT NULL'
add_index :post_actions, [:user_id]
add_index :user_uploads, [:user_id, :upload_id]
add_index :user_auth_token_logs, [:user_id]
add_index :topic_link, [:user_id]
end
end