Skip to content

Commit

Permalink
fixup! perf(sharing): Use getFirstNodeById() which is more performant
Browse files Browse the repository at this point in the history
  • Loading branch information
nickvergessen committed Jun 21, 2024
1 parent 5e48b86 commit 458203d
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 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) {
$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);
if (!$userFolder instanceof Node) {
throw new ShareNotFound();
}

$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');
}

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

$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

0 comments on commit 458203d

Please sign in to comment.