[Performance] Optimize queries in conversation/message finders (#364)
* [Performance] Optimize queries in conversation/message finders * Add message_finder spec * Fix message_finder spec
This commit is contained in:
@@ -66,7 +66,9 @@ class ConversationFinder
|
||||
end
|
||||
|
||||
def find_all_conversations
|
||||
@conversations = current_account.conversations.where(inbox_id: @inbox_ids)
|
||||
@conversations = current_account.conversations.includes(
|
||||
:assignee, :contact, :inbox
|
||||
).where(inbox_id: @inbox_ids)
|
||||
end
|
||||
|
||||
def filter_by_assignee_type
|
||||
|
||||
@@ -10,10 +10,14 @@ class MessageFinder
|
||||
|
||||
private
|
||||
|
||||
def messages
|
||||
return @conversation.messages if @params[:filter_internal_messages].blank?
|
||||
def conversation_messages
|
||||
@conversation.messages.includes(:attachment, user: { avatar_attachment: :blob })
|
||||
end
|
||||
|
||||
@conversation.messages.where.not('private = ? OR message_type = ?', true, 2)
|
||||
def messages
|
||||
return conversation_messages if @params[:filter_internal_messages].blank?
|
||||
|
||||
conversation_messages.where.not('private = ? OR message_type = ?', true, 2)
|
||||
end
|
||||
|
||||
def current_messages
|
||||
|
||||
@@ -23,7 +23,7 @@ json.data do
|
||||
else
|
||||
json.messages conversation.unread_messages.map(&:push_event_data)
|
||||
end
|
||||
json.inbox_id conversation.inbox.id
|
||||
json.inbox_id conversation.inbox_id
|
||||
json.status conversation.status_before_type_cast
|
||||
json.timestamp conversation.messages.last.try(:created_at).try(:to_i)
|
||||
json.user_last_seen_at conversation.user_last_seen_at.to_i
|
||||
|
||||
Reference in New Issue
Block a user