Skip to content

Commit dfd21de

Browse files
juliusknorrAndyScherzinger
authored andcommitted
feat: Pass limit/offset for searchByTag
Signed-off-by: Julius Härtl <jus@bitgrid.net>
1 parent b230e54 commit dfd21de

File tree

6 files changed

+27
-11
lines changed

6 files changed

+27
-11
lines changed

apps/dav/lib/Connector/Sabre/FilesReportPlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ protected function processFilterRulesForFileNodes(array $filterRules, ?int $limi
343343
}
344344

345345
if ($this->hasFilterFavorites($filterRules)) {
346-
$tmpNodes = $this->userFolder->searchByTag(ITags::TAG_FAVORITE, $this->userSession->getUser()->getUID());
346+
$tmpNodes = $this->userFolder->searchByTag(ITags::TAG_FAVORITE, $this->userSession->getUser()->getUID(), $limit ?? 0, $offset ?? 0);
347347
$nodes = $this->intersectNodes($nodes, $tmpNodes);
348348
if ($nodes === []) {
349349
// there cannot be a common match when nodes are empty early.

apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ public function testProcessFilterRulesSingle(): void {
495495
->with('OneTwoThree')
496496
->willReturn([$filesNode1, $filesNode2]);
497497

498-
$this->assertEquals([$filesNode1, $filesNode2], $this->invokePrivate($this->plugin, 'processFilterRulesForFileNodes', [$rules, 0, 0]));
498+
$this->assertEquals([$filesNode1, $filesNode2], $this->invokePrivate($this->plugin, 'processFilterRulesForFileNodes', [$rules, null, null]));
499499
}
500500

501501
public function testProcessFilterRulesAndCondition(): void {
@@ -934,11 +934,25 @@ public function testProcessFavoriteFilter(): void {
934934
['name' => '{http://owncloud.org/ns}favorite', 'value' => '1'],
935935
];
936936

937-
$this->privateTags->expects($this->once())
938-
->method('getFavorites')
939-
->willReturn(['456', '789']);
937+
$filesNode1 = $this->createMock(File::class);
938+
$filesNode1->expects($this->any())
939+
->method('getId')
940+
->willReturn(111);
941+
942+
$filesNode2 = $this->createMock(File::class);
943+
$filesNode2->expects($this->any())
944+
->method('getId')
945+
->willReturn(222);
946+
947+
$this->userFolder->expects($this->exactly(1))
948+
->method('searchByTag')
949+
->with('_$!<Favorite>!$_')
950+
->willReturn([
951+
$filesNode2,
952+
$filesNode1,
953+
]);
940954

941-
$this->assertEquals(['456', '789'], array_values($this->invokePrivate($this->plugin, 'processFilterRulesForFileIDs', [$rules])));
955+
$this->assertEquals([$filesNode1, $filesNode2], array_values($this->invokePrivate($this->plugin, 'processFilterRulesForFileNodes', [$rules, null, null])));
942956
}
943957

944958
public function filesBaseUriProvider() {

lib/private/Files/Node/Folder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@ public function searchByMime($mimetype) {
295295
* @param string $userId owner of the tags
296296
* @return Node[]
297297
*/
298-
public function searchByTag($tag, $userId) {
299-
$query = $this->queryFromOperator(new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'tagname', $tag), $userId);
298+
public function searchByTag($tag, $userId, int $limit = 0, int $offset = 0) {
299+
$query = $this->queryFromOperator(new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'tagname', $tag), $userId, $limit, $offset);
300300
return $this->search($query);
301301
}
302302

lib/private/Files/Node/LazyFolder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ public function searchByMime($mimetype) {
480480
/**
481481
* @inheritDoc
482482
*/
483-
public function searchByTag($tag, $userId) {
483+
public function searchByTag($tag, $userId, int $limit = 0, int $offset = 0) {
484484
return $this->__call(__FUNCTION__, func_get_args());
485485
}
486486

lib/private/Files/Node/NonExistingFolder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public function searchByMime($mimetype) {
150150
throw new NotFoundException();
151151
}
152152

153-
public function searchByTag($tag, $userId) {
153+
public function searchByTag($tag, $userId, int $limit = 0, int $offset = 0) {
154154
throw new NotFoundException();
155155
}
156156

lib/public/Files/Folder.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,12 @@ public function searchByMime($mimetype);
136136
*
137137
* @param string|int $tag tag name or tag id
138138
* @param string $userId owner of the tags
139+
* @param int $limit since 28.0.0
140+
* @param int $offset since 28.0.0
139141
* @return \OCP\Files\Node[]
140142
* @since 8.0.0
141143
*/
142-
public function searchByTag($tag, $userId);
144+
public function searchByTag($tag, $userId, int $limit = 0, int $offset = 0);
143145

144146
/**
145147
* search for files by system tag

0 commit comments

Comments
 (0)