From 52d3c74751b69e3d58807d105c6af6cf11a39616 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 18 Feb 2021 13:30:18 +0100 Subject: [PATCH] Don't load the session by default on getParticipantsForRoom Signed-off-by: Joas Schilling --- lib/Command/Room/TRoomCommand.php | 11 +++-------- lib/Controller/RoomController.php | 4 ++-- lib/Service/ParticipantService.php | 14 +++++++++----- lib/Signaling/Listener.php | 2 +- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/lib/Command/Room/TRoomCommand.php b/lib/Command/Room/TRoomCommand.php index 13f6d4efd14..c159c8b6c94 100644 --- a/lib/Command/Room/TRoomCommand.php +++ b/lib/Command/Room/TRoomCommand.php @@ -406,14 +406,9 @@ protected function completeParticipantValues(CompletionContext $context): array return []; } - $users = []; - $participants = $this->participantService->getParticipantsForRoom($room); - foreach ($participants as $participant) { - if ($participant->getAttendee()->getActorType() === Attendee::ACTOR_USERS - && stripos($participant->getAttendee()->getActorId(), $context->getCurrentWord()) !== false) { - $users[] = $participant->getAttendee()->getActorId(); - } - } + $users = array_filter($this->participantService->getParticipantUserIds($room), static function ($userId) use ($context) { + return stripos($userId, $context->getCurrentWord()) !== false; + }); return $users; } diff --git a/lib/Controller/RoomController.php b/lib/Controller/RoomController.php index 6d3b0e8e626..261aa0f6df2 100644 --- a/lib/Controller/RoomController.php +++ b/lib/Controller/RoomController.php @@ -477,7 +477,7 @@ protected function formatRoomV1(Room $room, ?Participant $currentParticipant): a $numActiveGuests = 0; $cleanGuests = false; $participantList = []; - $participants = $this->participantService->getParticipantsForRoom($room); + $participants = $this->participantService->getParticipantsForRoom($room, true); // FIXME NEEDS the session but can potentially kill APIv1? uasort($participants, function (Participant $participant1, Participant $participant2) { $s1 = $participant1->getSession() ? $participant1->getSession()->getLastPing() : 0; $s2 = $participant2->getSession() ? $participant2->getSession()->getLastPing() : 0; @@ -1110,7 +1110,7 @@ public function getParticipants(bool $includeStatus = false): DataResponse { } $maxPingAge = $this->timeFactory->getTime() - 100; - $participants = $this->participantService->getParticipantsForRoom($this->room); + $participants = $this->participantService->getParticipantsForRoom($this->room, true); // FIXME should return some what session info? $results = $headers = $statuses = []; if ($this->userId !== null diff --git a/lib/Service/ParticipantService.php b/lib/Service/ParticipantService.php index a788d009ca2..ddae0f8bb1e 100644 --- a/lib/Service/ParticipantService.php +++ b/lib/Service/ParticipantService.php @@ -583,21 +583,25 @@ public function getLastCommonReadChatMessageForMultipleRooms(array $roomIds): ar /** * @param Room $room + * @param bool $loadSession Loads a random session if possible for the users * @return Participant[] */ - public function getParticipantsForRoom(Room $room): array { + public function getParticipantsForRoom(Room $room, bool $loadSession = false): array { // FIXME Need to make sure a user is skipped when at least one session is in the call $query = $this->connection->getQueryBuilder(); $helper = new SelectHelper(); $helper->selectAttendeesTable($query); - $helper->selectSessionsTable($query); $query->from('talk_attendees', 'a') - ->leftJoin( + ->where($query->expr()->eq('a.room_id', $query->createNamedParameter($room->getId(), IQueryBuilder::PARAM_INT))); + + if ($loadSession) { + $helper->selectSessionsTable($query); + $query->leftJoin( 'a', 'talk_sessions', 's', $query->expr()->eq('s.attendee_id', 'a.id') - ) - ->where($query->expr()->eq('a.room_id', $query->createNamedParameter($room->getId(), IQueryBuilder::PARAM_INT))); + ); + } return $this->getParticipantsFromQuery($query, $room); } diff --git a/lib/Signaling/Listener.php b/lib/Signaling/Listener.php index d5625d1676a..44fe64724bf 100644 --- a/lib/Signaling/Listener.php +++ b/lib/Signaling/Listener.php @@ -103,7 +103,7 @@ protected static function registerInternalSignaling(IEventDispatcher $dispatcher /** @var ParticipantService $participantService */ $participantService = \OC::$server->query(ParticipantService::class); - $participants = $participantService->getParticipantsForRoom($room); + $participants = $participantService->getParticipantsForAllSessions($room); foreach ($participants as $participant) { $session = $participant->getSession(); if ($session instanceof Session) {