PERF: allow looking up incoming email by user_id

PERF: allow looking up incoming email by user_id

This speeds up the ability to remove users from the system

diff --git a/app/models/incoming_email.rb b/app/models/incoming_email.rb
index b355235..e985deb 100644
--- a/app/models/incoming_email.rb
+++ b/app/models/incoming_email.rb
@@ -52,4 +52,5 @@ end
 #  index_incoming_emails_on_error       (error)
 #  index_incoming_emails_on_message_id  (message_id)
 #  index_incoming_emails_on_post_id     (post_id)
+#  index_incoming_emails_on_user_id     (user_id) WHERE (user_id IS NOT NULL)
 #
diff --git a/db/migrate/20190426123026_add_incoming_email_by_user_id_index.rb b/db/migrate/20190426123026_add_incoming_email_by_user_id_index.rb
new file mode 100644
index 0000000..c870924
--- /dev/null
+++ b/db/migrate/20190426123026_add_incoming_email_by_user_id_index.rb
@@ -0,0 +1,5 @@
+class AddIncomingEmailByUserIdIndex < ActiveRecord::Migration[5.2]
+  def change
+    add_index :incoming_emails, [:user_id], where: 'user_id IS NOT NULL'
+  end
+end

GitHub sha: 378fe1c1

1 Like