PERF: add index on user auth tokens (for user lookups)

PERF: add index on user auth tokens (for user lookups)

This speeds up user destroy cause we cascade looking up all the tokens for a user

diff --git a/app/models/user_auth_token.rb b/app/models/user_auth_token.rb
index d79bdac..30a38c6 100644
--- a/app/models/user_auth_token.rb
+++ b/app/models/user_auth_token.rb
@@ -242,4 +242,5 @@ end
 #
 #  index_user_auth_tokens_on_auth_token       (auth_token) UNIQUE
 #  index_user_auth_tokens_on_prev_auth_token  (prev_auth_token) UNIQUE
+#  index_user_auth_tokens_on_user_id          (user_id)
 #
diff --git a/db/migrate/20190426123658_add_index_on_user_auth_token_user.rb b/db/migrate/20190426123658_add_index_on_user_auth_token_user.rb
new file mode 100644
index 0000000..7f0a050
--- /dev/null
+++ b/db/migrate/20190426123658_add_index_on_user_auth_token_user.rb
@@ -0,0 +1,5 @@
+class AddIndexOnUserAuthTokenUser < ActiveRecord::Migration[5.2]
+  def change
+    add_index :user_auth_tokens, [:user_id]
+  end
+end

GitHub sha: b8c65cc6

1 Like