Skip to content

Commit

Permalink
feat: Pass limit/offset for searchByTag
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliushaertl authored and AndyScherzinger committed Feb 27, 2024
1 parent b230e54 commit dfd21de
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion apps/dav/lib/Connector/Sabre/FilesReportPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Check notice

Code scanning / Psalm

PossiblyNullReference Note

Cannot call method getUID on possibly null value
$nodes = $this->intersectNodes($nodes, $tmpNodes);
if ($nodes === []) {
// there cannot be a common match when nodes are empty early.
Expand Down
24 changes: 19 additions & 5 deletions apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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('_$!<Favorite>!$_')
->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() {
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Files/Node/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Node/LazyFolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Node/NonExistingFolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
4 changes: 3 additions & 1 deletion lib/public/Files/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dfd21de

Please sign in to comment.