From e8ded6b524f023f2af4551cbc6401921a09a2907 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Thu, 5 Feb 2026 15:28:02 +0100 Subject: [PATCH 1/2] perf: Replace getById call with getFirstNodeById And some other minor cleanup in ViewInfoCache Signed-off-by: Carl Schwan --- lib/ViewInfoCache.php | 44 +++++++++++++++---------------------------- 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/lib/ViewInfoCache.php b/lib/ViewInfoCache.php index 0405fd0ab..621f51fc7 100644 --- a/lib/ViewInfoCache.php +++ b/lib/ViewInfoCache.php @@ -1,5 +1,7 @@ cacheId[$user][$fileId])) { $cache = $this->cacheId[$user][$fileId]; if ($cache['path'] === null) { @@ -43,12 +35,9 @@ public function getInfoById($user, $fileId, $path) { } /** - * @param string $user - * @param int $fileId - * @param string $filePath - * @return array + * @return array{path: string, exists: bool, is_dir: bool, view: string, node?: Node} */ - protected function findInfoById($user, $fileId, $filePath) { + protected function findInfoById(string $user, int $fileId, string $filePath): array { $cache = [ 'path' => $filePath, 'exists' => false, @@ -59,31 +48,28 @@ protected function findInfoById($user, $fileId, $filePath) { $notFound = false; try { $userFolder = $this->rootFolder->getUserFolder($user); - $entries = $userFolder->getById($fileId); - if (empty($entries)) { + $entry = $userFolder->getFirstNodeById($fileId); + if ($entry === null) { throw new NotFoundException('No entries returned'); } - /** @var Node $entry */ - $entry = array_shift($entries); $cache['path'] = $userFolder->getRelativePath($entry->getPath()); $cache['is_dir'] = $entry instanceof Folder; $cache['exists'] = true; $cache['node'] = $entry; - } catch (NotFoundException $e) { + } catch (NotFoundException) { // The file was not found in the normal view, // maybe it is in the trashbin? try { - /** @var Folder $userTrashBin */ $userTrashBin = $this->rootFolder->get('/' . $user . '/files_trashbin'); - $entries = $userTrashBin->getById($fileId); - if (empty($entries)) { + if (!$userTrashBin instanceof Folder) { + throw new NotFoundException('No trash bin found for user: ' . $user); + } + $entry = $userTrashBin->getFirstNodeById($fileId); + if ($entry === null) { throw new NotFoundException('No entries returned'); } - /** @var Node $entry */ - $entry = array_shift($entries); - $cache = [ 'path' => $userTrashBin->getRelativePath($entry->getPath()), 'exists' => true, @@ -91,7 +77,7 @@ protected function findInfoById($user, $fileId, $filePath) { 'view' => 'trashbin', 'node' => $entry, ]; - } catch (NotFoundException $e) { + } catch (NotFoundException) { $notFound = true; } } From 582d517fa6234c9e97ce880869923a56fb8b8d83 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Thu, 5 Feb 2026 15:31:00 +0100 Subject: [PATCH 2/2] chore: bump nextcloud/ocp Fix psalm when running locally Signed-off-by: Carl Schwan --- tests/ViewInfoCacheTest.php | 16 ++++++++-------- vendor-bin/psalm/composer.lock | 14 +++++++------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/ViewInfoCacheTest.php b/tests/ViewInfoCacheTest.php index 619ede4ca..786a4348e 100644 --- a/tests/ViewInfoCacheTest.php +++ b/tests/ViewInfoCacheTest.php @@ -239,9 +239,9 @@ public function testFindInfoById(string $user, int $fileId, string $filename, ?s ->willReturn($userFolder); if ($path === null) { $userFolder->expects($this->once()) - ->method('getById') + ->method('getFirstNodeById') ->with($fileId) - ->willThrowException(new NotFoundException()); + ->willReturn(null); $userTrashBin = $this->createMock(Folder::class); $this->rootFolder->expects($this->once()) @@ -250,9 +250,9 @@ public function testFindInfoById(string $user, int $fileId, string $filename, ?s ->willReturn($userTrashBin); if ($pathTrash === null) { $userTrashBin->expects($this->once()) - ->method('getById') + ->method('getFirstNodeById') ->with($fileId) - ->willThrowException(new NotFoundException()); + ->willReturn(null); } else { $node = $this->createMock($isDir ? Folder::class : File::class); $node @@ -264,9 +264,9 @@ public function testFindInfoById(string $user, int $fileId, string $filename, ?s ->willReturn($pathTrash); $userTrashBin->expects($this->once()) - ->method('getById') + ->method('getFirstNodeById') ->with($fileId) - ->willReturn([2 => $node]); + ->willReturn($node); $expected['node'] = $node; $expectedCache[$user][$fileId]['node'] = $node; } @@ -281,9 +281,9 @@ public function testFindInfoById(string $user, int $fileId, string $filename, ?s ->willReturn($path); $userFolder->expects($this->once()) - ->method('getById') + ->method('getFirstNodeById') ->with($fileId) - ->willReturn([3 => $node]); + ->willReturn($node); $expected['node'] = $node; $expectedCache[$user][$fileId]['node'] = $node; } diff --git a/vendor-bin/psalm/composer.lock b/vendor-bin/psalm/composer.lock index 2f0d4d08c..4e7b010f5 100644 --- a/vendor-bin/psalm/composer.lock +++ b/vendor-bin/psalm/composer.lock @@ -1632,16 +1632,16 @@ "source": { "type": "git", "url": "https://github.com/nextcloud-deps/ocp.git", - "reference": "bc6cd08b280bd4be8ae64faaed057ca2a18bdf6d" + "reference": "c8103ef4440e6759b4c9ed9edbefec028d1b9196" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nextcloud-deps/ocp/zipball/bc6cd08b280bd4be8ae64faaed057ca2a18bdf6d", - "reference": "bc6cd08b280bd4be8ae64faaed057ca2a18bdf6d", + "url": "https://api.github.com/repos/nextcloud-deps/ocp/zipball/c8103ef4440e6759b4c9ed9edbefec028d1b9196", + "reference": "c8103ef4440e6759b4c9ed9edbefec028d1b9196", "shasum": "" }, "require": { - "php": "~8.1 || ~8.2 || ~8.3 || ~8.4", + "php": "~8.1 || ~8.2 || ~8.3 || ~8.4 || ~8.5", "psr/clock": "^1.0", "psr/container": "^2.0.2", "psr/event-dispatcher": "^1.0", @@ -1651,7 +1651,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "33.0.0-dev" + "dev-master": "34.0.0-dev" } }, "notification-url": "https://packagist.org/downloads/", @@ -1673,7 +1673,7 @@ "issues": "https://github.com/nextcloud-deps/ocp/issues", "source": "https://github.com/nextcloud-deps/ocp/tree/master" }, - "time": "2025-11-04T00:51:09+00:00" + "time": "2026-02-05T13:36:04+00:00" }, { "name": "nikic/php-parser", @@ -3493,5 +3493,5 @@ "platform-overrides": { "php": "8.2.27" }, - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.9.0" }