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:
Sony Mathew
2020-09-19 12:46:34 +05:30
committed by GitHub
parent 74d07c876e
commit fc7b84d612
5 changed files with 6 additions and 6 deletions

View File

@@ -12,9 +12,9 @@ end
json.id conversation.display_id
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
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
json.inbox_id conversation.inbox_id