summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2024-06-20 22:40:09 +0200
committerJoas Schilling <coding@schilljs.com>2024-07-11 17:57:46 +0200
commitcd6a4727ebfd827929242b7615220ba913d48d65 (patch)
tree6647eaa3d905467f6a73d4b1d98141717601f376
parente765daa68dcdaa120c42af07597d84392604b818 (diff)
perf(sharing): Use getFirstNodeById() which is more performant
As we don't care which node we get for rendering the message Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r--lib/Chat/Parser/SystemMessage.php32
-rw-r--r--tests/php/Chat/Parser/SystemMessageTest.php6
2 files changed, 22 insertions, 16 deletions
diff --git a/lib/Chat/Parser/SystemMessage.php b/lib/Chat/Parser/SystemMessage.php
index d463877a5..499950e19 100644
--- a/lib/Chat/Parser/SystemMessage.php
+++ b/lib/Chat/Parser/SystemMessage.php
@@ -756,17 +756,18 @@ class SystemMessage implements IEventListener {
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');
@@ -774,12 +775,13 @@ class SystemMessage implements IEventListener {
/** @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();
diff --git a/tests/php/Chat/Parser/SystemMessageTest.php b/tests/php/Chat/Parser/SystemMessageTest.php
index 66dee3848..36c2f0e5d 100644
--- a/tests/php/Chat/Parser/SystemMessageTest.php
+++ b/tests/php/Chat/Parser/SystemMessageTest.php
@@ -873,7 +873,11 @@ class SystemMessageTest extends TestCase {
->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([]);