feat: preload messages_count
This commit is contained in:
@@ -60,6 +60,12 @@ class Conversations::FilterService < FilterService
|
||||
@conversations = @conversations.includes(
|
||||
:taggings, :inbox, { assignee: { avatar_attachment: [:blob] } }, { contact: { avatar_attachment: [:blob] } }, :team
|
||||
)
|
||||
|
||||
@conversations = @conversations
|
||||
.left_joins(:messages)
|
||||
.select('conversations.*, COUNT(DISTINCT messages.id) AS message_count')
|
||||
.group('conversations.id')
|
||||
|
||||
@conversations.latest.page(current_page)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,7 +17,7 @@ json.meta do
|
||||
end
|
||||
|
||||
json.id conversation.display_id
|
||||
if conversation.messages.count.zero?
|
||||
if conversation.message_count.zero?
|
||||
json.messages []
|
||||
elsif conversation.unread_incoming_messages.count.zero?
|
||||
json.messages [conversation.messages.includes([{ attachments: [{ file_attachment: [:blob] }] }]).last.try(:push_event_data)]
|
||||
|
||||
Reference in New Issue
Block a user