From dfd21deb7e800dcdf0ee70b167b4e7edc1cdd949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Tue, 11 Jul 2023 14:54:02 +0200 Subject: [PATCH] feat: Pass limit/offset for searchByTag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- .../lib/Connector/Sabre/FilesReportPlugin.php | 2 +- .../Connector/Sabre/FilesReportPluginTest.php | 24 +++++++++++++++---- lib/private/Files/Node/Folder.php | 4 ++-- lib/private/Files/Node/LazyFolder.php | 2 +- lib/private/Files/Node/NonExistingFolder.php | 2 +- lib/public/Files/Folder.php | 4 +++- 6 files changed, 27 insertions(+), 11 deletions(-) diff --git a/apps/dav/lib/Connector/Sabre/FilesReportPlugin.php b/apps/dav/lib/Connector/Sabre/FilesReportPlugin.php index 7cfba3a51904d..d0141b517e03e 100644 --- a/apps/dav/lib/Connector/Sabre/FilesReportPlugin.php +++ b/apps/dav/lib/Connector/Sabre/FilesReportPlugin.php @@ -343,7 +343,7 @@ protected function processFilterRulesForFileNodes(array $filterRules, ?int $limi } if ($this->hasFilterFavorites($filterRules)) { - $tmpNodes = $this->userFolder->searchByTag(ITags::TAG_FAVORITE, $this->userSession->getUser()->getUID()); + $tmpNodes = $this->userFolder->searchByTag(ITags::TAG_FAVORITE, $this->userSession->getUser()->getUID(), $limit ?? 0, $offset ?? 0); $nodes = $this->intersectNodes($nodes, $tmpNodes); if ($nodes === []) { // there cannot be a common match when nodes are empty early. diff --git a/apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php index c636d16358dad..1d333468592ee 100644 --- a/apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php @@ -495,7 +495,7 @@ public function testProcessFilterRulesSingle(): void { ->with('OneTwoThree') ->willReturn([$filesNode1, $filesNode2]); - $this->assertEquals([$filesNode1, $filesNode2], $this->invokePrivate($this->plugin, 'processFilterRulesForFileNodes', [$rules, 0, 0])); + $this->assertEquals([$filesNode1, $filesNode2], $this->invokePrivate($this->plugin, 'processFilterRulesForFileNodes', [$rules, null, null])); } public function testProcessFilterRulesAndCondition(): void { @@ -934,11 +934,25 @@ public function testProcessFavoriteFilter(): void { ['name' => '{http://owncloud.org/ns}favorite', 'value' => '1'], ]; - $this->privateTags->expects($this->once()) - ->method('getFavorites') - ->willReturn(['456', '789']); + $filesNode1 = $this->createMock(File::class); + $filesNode1->expects($this->any()) + ->method('getId') + ->willReturn(111); + + $filesNode2 = $this->createMock(File::class); + $filesNode2->expects($this->any()) + ->method('getId') + ->willReturn(222); + + $this->userFolder->expects($this->exactly(1)) + ->method('searchByTag') + ->with('_$!!$_') + ->willReturn([ + $filesNode2, + $filesNode1, + ]); - $this->assertEquals(['456', '789'], array_values($this->invokePrivate($this->plugin, 'processFilterRulesForFileIDs', [$rules]))); + $this->assertEquals([$filesNode1, $filesNode2], array_values($this->invokePrivate($this->plugin, 'processFilterRulesForFileNodes', [$rules, null, null]))); } public function filesBaseUriProvider() { diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php index c7462572fed06..dd7fe466a34a4 100644 --- a/lib/private/Files/Node/Folder.php +++ b/lib/private/Files/Node/Folder.php @@ -295,8 +295,8 @@ public function searchByMime($mimetype) { * @param string $userId owner of the tags * @return Node[] */ - public function searchByTag($tag, $userId) { - $query = $this->queryFromOperator(new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'tagname', $tag), $userId); + public function searchByTag($tag, $userId, int $limit = 0, int $offset = 0) { + $query = $this->queryFromOperator(new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'tagname', $tag), $userId, $limit, $offset); return $this->search($query); } diff --git a/lib/private/Files/Node/LazyFolder.php b/lib/private/Files/Node/LazyFolder.php index e30cfea693ec1..e5a9a3b2ea6e8 100644 --- a/lib/private/Files/Node/LazyFolder.php +++ b/lib/private/Files/Node/LazyFolder.php @@ -480,7 +480,7 @@ public function searchByMime($mimetype) { /** * @inheritDoc */ - public function searchByTag($tag, $userId) { + public function searchByTag($tag, $userId, int $limit = 0, int $offset = 0) { return $this->__call(__FUNCTION__, func_get_args()); } diff --git a/lib/private/Files/Node/NonExistingFolder.php b/lib/private/Files/Node/NonExistingFolder.php index 34621b18f19a3..e4b2df5a724f4 100644 --- a/lib/private/Files/Node/NonExistingFolder.php +++ b/lib/private/Files/Node/NonExistingFolder.php @@ -150,7 +150,7 @@ public function searchByMime($mimetype) { throw new NotFoundException(); } - public function searchByTag($tag, $userId) { + public function searchByTag($tag, $userId, int $limit = 0, int $offset = 0) { throw new NotFoundException(); } diff --git a/lib/public/Files/Folder.php b/lib/public/Files/Folder.php index eb81a2098ec33..7e0730137487b 100644 --- a/lib/public/Files/Folder.php +++ b/lib/public/Files/Folder.php @@ -136,10 +136,12 @@ public function searchByMime($mimetype); * * @param string|int $tag tag name or tag id * @param string $userId owner of the tags + * @param int $limit since 28.0.0 + * @param int $offset since 28.0.0 * @return \OCP\Files\Node[] * @since 8.0.0 */ - public function searchByTag($tag, $userId); + public function searchByTag($tag, $userId, int $limit = 0, int $offset = 0); /** * search for files by system tag