Save the "count unread messages" query, when the last read is the last room messages

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2020-09-22 19:52:43 +02:00
Родитель 20737ff49e
Коммит b3394e6235
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 7076EA9751AACDDA
1 изменённых файлов: 7 добавлений и 1 удалений

Просмотреть файл

@ -498,7 +498,13 @@ class RoomController extends AEnvironmentAwareController {
$lastReadMessage = $this->chatManager->getLastReadMessageFromLegacy($room, $currentUser);
$currentParticipant->setLastReadMessage($lastReadMessage);
}
$roomData['unreadMessages'] = $this->chatManager->getUnreadCount($room, $lastReadMessage);
if ($room->getLastMessage() && $lastReadMessage === (int) $room->getLastMessage()->getId()) {
// When the last message is the last read message, there are no unread messages,
// so we can save the query.
$roomData['unreadMessages'] = 0;
} else {
$roomData['unreadMessages'] = $this->chatManager->getUnreadCount($room, $lastReadMessage);
}
$lastMention = $currentParticipant->getLastMentionMessage();
$roomData['unreadMention'] = $lastMention !== 0 && $lastReadMessage < $lastMention;