Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable29] perf(sharing): Use getFirstNodeById() which is more performant #12554

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$userFolder->getRelativePath($fullPath) is the "correct" way to do this.

} 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
Loading