From 47a796b7a865ce4efd0c9023a41d548037883895 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 +++++++++++++------------------------ tests/ViewInfoCacheTest.php | 11 +++++----- 2 files changed, 20 insertions(+), 35 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; } } diff --git a/tests/ViewInfoCacheTest.php b/tests/ViewInfoCacheTest.php index 619ede4ca..a4716a4c2 100644 --- a/tests/ViewInfoCacheTest.php +++ b/tests/ViewInfoCacheTest.php @@ -27,7 +27,6 @@ use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IRootFolder; -use OCP\Files\NotFoundException; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; @@ -57,7 +56,7 @@ public function getCache(array $methods = []): ViewInfoCache|MockObject { public static function dataGetInfoById(): array { return [ [ - 'user', 23, 'path', [], true, 'findInfoById', + 'user', 23, 'path', [], true, ['findInfoById'], ], [ 'user', @@ -69,7 +68,7 @@ public static function dataGetInfoById(): array { ] ], true, - 'findInfoById', + ['findInfoById'], ], [ 'user', @@ -81,7 +80,7 @@ public static function dataGetInfoById(): array { ] ], true, - 'findInfoById', + ['findInfoById'], ], [ 'user', @@ -111,7 +110,7 @@ public static function dataGetInfoById(): array { } #[DataProvider('dataGetInfoById')] - public function testGetInfoById(string $user, int $id, string|array $path, array $cache, bool $callsFind, string|array $expected): void { + public function testGetInfoById(string $user, int $id, string|array $path, array $cache, bool $callsFind, array $expected): void { $infoCache = $this->getCache([ 'findInfoById', ]); @@ -119,7 +118,7 @@ public function testGetInfoById(string $user, int $id, string|array $path, array if ($callsFind) { $infoCache->expects($this->once()) ->method('findInfoById') - ->willReturn('findInfoById'); + ->willReturn(['findInfoById']); } else { $infoCache->expects($this->never()) ->method('findInfoById'); From f55f5ada3c27b44898ebdefccca8509474abb11a 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 a4716a4c2..e667dd0c4 100644 --- a/tests/ViewInfoCacheTest.php +++ b/tests/ViewInfoCacheTest.php @@ -238,9 +238,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()) @@ -249,9 +249,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 @@ -263,9 +263,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; } @@ -280,9 +280,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" }