Chore: Fix N+1 queries in dashboard side (#1254)
* Chore: Fix N+1 queries in dashboard side Fixed a couple of N+1 queries fired on the dashboard side of the app to improve performance.
This commit is contained in:
parent
74d07c876e
commit
fc7b84d612
5 changed files with 6 additions and 6 deletions
|
@ -1,7 +1,7 @@
|
||||||
class Api::V1::Accounts::Contacts::ConversationsController < Api::V1::Accounts::BaseController
|
class Api::V1::Accounts::Contacts::ConversationsController < Api::V1::Accounts::BaseController
|
||||||
def index
|
def index
|
||||||
@conversations = Current.account.conversations.includes(
|
@conversations = Current.account.conversations.includes(
|
||||||
:assignee, :contact, :inbox
|
:assignee, :contact, :inbox, :taggings
|
||||||
).where(inbox_id: inbox_ids, contact_id: permitted_params[:contact_id])
|
).where(inbox_id: inbox_ids, contact_id: permitted_params[:contact_id])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,6 @@ class Api::V1::Accounts::ContactsController < Api::V1::Accounts::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch_contact
|
def fetch_contact
|
||||||
@contact = Current.account.contacts.find(params[:id])
|
@contact = Current.account.contacts.includes(contact_inboxes: [:inbox]).find(params[:id])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -62,7 +62,7 @@ class ConversationFinder
|
||||||
|
|
||||||
def find_all_conversations
|
def find_all_conversations
|
||||||
@conversations = current_account.conversations.includes(
|
@conversations = current_account.conversations.includes(
|
||||||
:assignee, :inbox, contact: [:avatar_attachment]
|
:assignee, :inbox, :taggings, contact: [:avatar_attachment]
|
||||||
).where(inbox_id: @inbox_ids)
|
).where(inbox_id: @inbox_ids)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ class MessageFinder
|
||||||
private
|
private
|
||||||
|
|
||||||
def conversation_messages
|
def conversation_messages
|
||||||
@conversation.messages.includes(:attachments, user: { avatar_attachment: :blob })
|
@conversation.messages.includes(:attachments, :sender)
|
||||||
end
|
end
|
||||||
|
|
||||||
def messages
|
def messages
|
||||||
|
|
|
@ -12,9 +12,9 @@ end
|
||||||
|
|
||||||
json.id conversation.display_id
|
json.id conversation.display_id
|
||||||
if conversation.unread_incoming_messages.count.zero?
|
if conversation.unread_incoming_messages.count.zero?
|
||||||
json.messages [conversation.messages.last.try(:push_event_data)]
|
json.messages [conversation.messages.includes([{ attachments: [{ file_attachment: [:blob] }] }]).last.try(:push_event_data)]
|
||||||
else
|
else
|
||||||
json.messages conversation.unread_messages.includes([:user, :attachments]).map(&:push_event_data)
|
json.messages conversation.unread_messages.includes([:user, { attachments: [{ file_attachment: [:blob] }] }]).map(&:push_event_data)
|
||||||
end
|
end
|
||||||
|
|
||||||
json.inbox_id conversation.inbox_id
|
json.inbox_id conversation.inbox_id
|
||||||
|
|
Loading…
Reference in a new issue