diff options
author | Joas Schilling <coding@schilljs.com> | 2020-09-22 20:52:43 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2020-09-22 20:52:43 +0300 |
commit | b3394e623590fc1abb826c3b395e14f763f407e4 (patch) | |
tree | 0ec225273015ac1930db00a6e0f92a9ab1f68184 /lib | |
parent | 20737ff49eb12a54bbff144d09dcf5635c92e480 (diff) |
Save the "count unread messages" query, when the last read is the last room messages
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Controller/RoomController.php | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php index 43fbd040d..53c95f17c 100644 --- a/lib/Controller/RoomController.php +++ b/lib/Controller/RoomController.php @@ -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; |