Skip to content

Commit

Permalink
perf(sharing): Use getFirstNodeById() which is more performant
Browse files Browse the repository at this point in the history
As we don't care which node we get for rendering the message

Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Jul 11, 2024
1 parent e765daa commit cd6a472
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
32 changes: 17 additions & 15 deletions lib/Chat/Parser/SystemMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -756,30 +756,32 @@ protected function getFileFromShare(Room $room, ?Participant $participant, strin
if ($participant && $participant->getAttendee()->getActorType() === Attendee::ACTOR_USERS) {
if ($share->getShareOwner() !== $participant->getAttendee()->getActorId()) {
$userFolder = $this->rootFolder->getUserFolder($participant->getAttendee()->getActorId());
if ($userFolder instanceof Node) {
$userNodes = $userFolder->getById($share->getNodeId());
if (!$userFolder instanceof Node) {
throw new ShareNotFound();
}

if (empty($userNodes)) {
// FIXME This should be much more sensible, e.g.
// 1. Only be executed on "Waiting for new messages"
// 2. Once per request
\OC_Util::tearDownFS();
\OC_Util::setupFS($participant->getAttendee()->getActorId());
$userNodes = $userFolder->getById($share->getNodeId());
}
$node = $userFolder->getFirstNodeById($share->getNodeId());
if (!$node instanceof Node) {
// FIXME This should be much more sensible, e.g.
// 1. Only be executed on "Waiting for new messages"
// 2. Once per request
\OC_Util::tearDownFS();
\OC_Util::setupFS($participant->getAttendee()->getActorId());
$userNodes = $userFolder->getById($share->getNodeId());

if (empty($userNodes)) {
throw new NotFoundException('File was not found');
}

/** @var Node $node */
$node = reset($userNodes);
$fullPath = $node->getPath();
$pathSegments = explode('/', $fullPath, 4);
$name = $node->getName();
$size = $node->getSize();
$path = $pathSegments[3] ?? $name;
}

$fullPath = $node->getPath();
$pathSegments = explode('/', $fullPath, 4);
$name = $node->getName();
$size = $node->getSize();
$path = $pathSegments[3] ?? $name;
} else {
$node = $share->getNode();
$name = $node->getName();
Expand Down
6 changes: 5 additions & 1 deletion tests/php/Chat/Parser/SystemMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,11 @@ public function testGetFileFromShareForRecipientThrows() {
->willReturn($share);

$userFolder = $this->createMock(Folder::class);
$userFolder->expects($this->exactly(2))
$userFolder->expects($this->once())
->method('getFirstNodeById')
->with('54')
->willReturn(null);
$userFolder->expects($this->once())
->method('getById')
->with('54')
->willReturn([]);
Expand Down

0 comments on commit cd6a472

Please sign in to comment.