PERF: Add `index_reply_id_on_post_replies`.

PERF: Add index_reply_id_on_post_replies.

Speeds up the reference posts query in Email::Sender#send.

diff --git a/db/migrate/20190410055459_add_index_reply_id_on_post_replies.rb b/db/migrate/20190410055459_add_index_reply_id_on_post_replies.rb
new file mode 100644
index 0000000..0577049
--- /dev/null
+++ b/db/migrate/20190410055459_add_index_reply_id_on_post_replies.rb
@@ -0,0 +1,5 @@
+class AddIndexReplyIdOnPostReplies < ActiveRecord::Migration[5.2]
+  def change
+    add_index :post_replies, :reply_id
+  end
+end
diff --git a/lib/email/sender.rb b/lib/email/sender.rb
index 0de51e5..488a15e 100644
--- a/lib/email/sender.rb
+++ b/lib/email/sender.rb
@@ -110,7 +110,8 @@ module Email
           "<topic/#{topic_id}/#{post_id}@#{host}>"
 
         referenced_posts = Post.includes(:incoming_email)
-          .where(id: PostReply.where(reply_id: post_id).select(:post_id))
+          .joins("INNER JOIN post_replies ON post_replies.post_id = posts.id ")
+          .where("post_replies.reply_id = ?", post_id)
           .order(id: :desc)
 
         referenced_post_message_ids = referenced_posts.map do |referenced_post|

GitHub sha: bac1bcc7

nice, that column name though reply_id is a problem imo. It should be reply_post_id. The current name is just too vague.

Should I slap a followup on this ?