PERF: Add index_reply_id_on_post_replies.

Speeds up the reference posts query in `Email::Sender#send`.
This commit is contained in:
Guo Xiang Tan 2019-04-10 13:56:44 +08:00
parent bfdd0fe64c
commit bac1bcc79f
2 changed files with 7 additions and 1 deletions

View File

@ -0,0 +1,5 @@
class AddIndexReplyIdOnPostReplies < ActiveRecord::Migration[5.2]
def change
add_index :post_replies, :reply_id
end
end

View File

@ -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|