Skip to content

Commit

Permalink
feat: Use file cache query builder for searching for favorites
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliushaertl committed Jul 11, 2023
1 parent 2dfd9ee commit d438f85
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
28 changes: 28 additions & 0 deletions apps/dav/lib/Connector/Sabre/FilesReportPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use OCP\Files\Node as INode;
use OCP\IGroupManager;
use OCP\ITagManager;
use OCP\ITags;
use OCP\IUserSession;
use OCP\SystemTag\ISystemTagManager;
use OCP\SystemTag\ISystemTagObjectMapper;
Expand Down Expand Up @@ -363,6 +364,33 @@ protected function processFilterRulesForFileNodes(array $filterRules, ?int $limi
}
}

$ns = '{' . $this::NS_OWNCLOUD . '}';
$favoriteFilter = null;
foreach ($filterRules as $filterRule) {
if ($filterRule['name'] === $ns . 'favorite') {
$favoriteFilter = true;
}
}

if ($favoriteFilter !== null) {
$tmpNodes = $this->userFolder->searchByTag(ITags::TAG_FAVORITE, $this->userSession->getUser()->getUID());

Check notice

Code scanning / Psalm

PossiblyNullReference Note

Cannot call method getUID on possibly null value
if (count($nodes) === 0) {
$nodes = $tmpNodes;
} else {
$nodes = array_uintersect($nodes, $tmpNodes, function (INode $a, INode $b): int {
return $a->getId() - $b->getId();
});
}
if ($nodes === []) {
// there cannot be a common match when nodes are empty early.
return $nodes;
}

if ($limit !== null || $offset !== null) {
$nodes = array_slice($nodes, $offset, $limit);

Check notice

Code scanning / Psalm

PossiblyNullArgument Note

Argument 2 of array_slice cannot be null, possibly null value provided
}
}

return $nodes;
}

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

0 comments on commit d438f85

Please sign in to comment.