Skip to content

Conversation

@blizzz
Copy link
Member

@blizzz blizzz commented May 2, 2023

combined backport of #37961 and #37969, plus PHP 7.4 compatibility change

This is preliminary.

blizzz added 3 commits May 2, 2023 09:41
Target case is photos app: when visiting the tags category, all systemtags
of the whole cloud are retrieved. In subequent steps the next tag is
requested until the browser view is filled with tag tiles (i.e. previews
are requested just as well).

With this approach, we incorpoate the dav search and look for user related
tags that are used by them, and already returns the statistics (number of
files tagged with the respective tag) as well as a file id for the purpose
to load the preview. This defaults to the file with the highest id.

Call:
curl -s -u 'user:password' \
  'https://my.nc.srv/remote.php/dav/systemtags-current' \
  -X PROPFIND -H 'Accept: text/plain' \
  -H 'Accept-Language: en-US,en;q=0.5'  -H 'Depth: 1' \
  -H 'Content-Type: text/plain;charset=UTF-8' \
  --data @/home/doe/request-systemtag-props.xml

With request-systemtag-props.xml:
<?xml version="1.0" encoding="UTF-8"?>
<d:propfind xmlns:d="DAV:">
        <d:prop xmlns:oc="http://owncloud.org/ns" xmlns:nc="http://nextcloud.org/ns">
                <oc:id/>
                <oc:display-name/>
                <oc:user-visible/>
                <oc:user-assignable/>
                <oc:can-assign/>
                <nc:files-assigned/>
                <nc:reference-fileid/>
        </d:prop>
</d:propfind>

Example output:
  …
  <d:response>
    <d:href>/master/remote.php/dav/systemtags/84</d:href>
    <d:propstat>
      <d:prop>
        <oc:id>84</oc:id>
        <oc:display-name>Computer</oc:display-name>
        <oc:user-visible>true</oc:user-visible>
        <oc:user-assignable>true</oc:user-assignable>
        <oc:can-assign>true</oc:can-assign>
        <nc:files-assigned>42</nc:files-assigned>
        <nc:reference-fileid>924022</nc:reference-fileid>
      </d:prop>
      <d:status>HTTP/1.1 200 OK</d:status>
    </d:propstat>
  </d:response>
  <d:response>
    <d:href>/remote.php/dav/systemtags/97</d:href>
    <d:propstat>
      <d:prop>
        <oc:id>97</oc:id>
        <oc:display-name>Bear</oc:display-name>
        <oc:user-visible>true</oc:user-visible>
        <oc:user-assignable>true</oc:user-assignable>
        <oc:can-assign>true</oc:can-assign>
        <nc:files-assigned>1</nc:files-assigned>
        <nc:reference-fileid>923422</nc:reference-fileid>
      </d:prop>
      <d:status>HTTP/1.1 200 OK</d:status>
    </d:propstat>
  </d:response>
  …

Signed-off-by: Arthur Schiwon <[email protected]>
- uses DAV search approach against valid files joined by systemtag selector
- reduced table join for tag/systemtag search
- supports pagination
- no changes to the output formats or similar

Example request body:

<?xml version="1.0"?>
<oc:filter-files xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns" xmlns:nc="http://nextcloud.org/ns" xmlns:ocs="http://open-collaboration-services.org/ns">
  <d:prop>
    <d:getcontentlength/>
    <d:getcontenttype/>
    <d:getetag/>
    <d:getlastmodified/>
    <d:resourcetype/>
    <nc:face-detections/>
    <nc:file-metadata-size/>
    <nc:has-preview/>
    <nc:realpath/>
    <oc:favorite/>
    <oc:fileid/>
    <oc:permissions/>
    <nc:nbItems/>
  </d:prop>
  <oc:filter-rules>
    <oc:systemtag>32</oc:systemtag>
  </oc:filter-rules>
  <d:limit>
    <d:nresults>50</d:nresults>
    <nc:firstresult>0</nc:firstresult>
  </d:limit>
</oc:filter-files>

Signed-off-by: Arthur Schiwon <[email protected]>
Signed-off-by: Arthur Schiwon <[email protected]>
}

return $nodes;
}

Check notice

Code scanning / Psalm

PossiblyNullReference

Cannot call method getUID on possibly null value
if ($node instanceof \OCP\Files\File) {
return new File($this->fileView, $node);
} elseif ($node instanceof \OCP\Files\Folder) {
return new Directory($this->fileView, $node);

Check failure

Code scanning / Psalm

InvalidReturnType

Not all code paths of OCA\DAV\Connector\Sabre\FilesReportPlugin::wrapNode end in a return statement, return type Sabre\DAV\INode expected
}

$userFolder = $this->rootFolder->getUserFolder($user->getUID());
$result = $userFolder->getSystemTags('image');

Check failure

Code scanning / Psalm

UndefinedInterfaceMethod

Method OCP\Files\Folder::getSystemTags does not exist
throw new \InvalidArgumentException('searching by owner is only allows on the users home folder');
}

protected function getCachesAndMountpointsForSearch(bool $limitToHome = false): array {

Check failure

Code scanning / Psalm

InvalidDocblock

Unexpected brace character in docblock for OC\Files\Node\Folder::getCachesAndMountpointsForSearch
}

return $nodes;
}

Check failure

Code scanning / Psalm

UndefinedInterfaceMethod

Method OCP\Files\Folder::searchBySystemTag does not exist
$searchExpr = $this->searchBuilder->searchOperatorToDBExpr($builder, $filter);
if ($searchExpr) {
$query->andWhere($searchExpr);
if ($searchQuery->getSearchOperation() instanceof ISearchComparison && $searchQuery->getSearchOperation()->getField() === 'systemtag') {

Check failure

Code scanning / Psalm

UndefinedInterfaceMethod

Method OCP\Files\Search\ISearchOperator::getField does not exist
@blizzz blizzz closed this Jul 11, 2023
@skjnldsv skjnldsv deleted the backport/37961+37969/stable25 branch March 14, 2024 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants