feat(perf): improve performance of conversation filter API [CW-1605] (#7120)

* feat(perf): don't use count

* feat(perf): include messages in the conversation query

* feat: include contact inboxes

* refactor: use blank?
This commit is contained in:
Shivam Mishra
2023-05-22 16:03:11 +05:30
committed by GitHub
parent 9553329092
commit 958c0d7946
2 changed files with 3 additions and 2 deletions

View File

@@ -58,8 +58,9 @@ class Conversations::FilterService < FilterService
def conversations
@conversations = @conversations.includes(
:taggings, :inbox, { assignee: { avatar_attachment: [:blob] } }, { contact: { avatar_attachment: [:blob] } }, :team
:taggings, :inbox, { assignee: { avatar_attachment: [:blob] } }, { contact: { avatar_attachment: [:blob] } }, :team, :messages, :contact_inbox
)
@conversations.latest.page(current_page)
end
end

View File

@@ -17,7 +17,7 @@ json.meta do
end
json.id conversation.display_id
if conversation.messages.count.zero?
if conversation.messages.first.blank?
json.messages []
elsif conversation.unread_incoming_messages.count.zero?
json.messages [conversation.messages.includes([{ attachments: [{ file_attachment: [:blob] }] }]).last.try(:push_event_data)]