Skip to content

Commit

Permalink
Adjust REPORT search query, perf and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Petry committed Mar 17, 2017
1 parent 5505a2d commit 099a9f9
Show file tree
Hide file tree
Showing 3 changed files with 218 additions and 98 deletions.
20 changes: 14 additions & 6 deletions apps/dav/lib/Connector/Sabre/FilesReportPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ public function onReport($reportName, $report, $uri) {
if (empty($filterRules['systemtag']) && is_null($filterRules['favorite'])) {
// load all
$results = $reportTargetNode->getChildren();
$results = $this->slice($results, $report);
} else {
// gather all file ids matching filter
try {
Expand All @@ -190,16 +191,14 @@ public function onReport($reportName, $report, $uri) {
throw new PreconditionFailed('Cannot filter by non-existing tag', 0, $e);
}

// pre-slice the results if needed for pagination to not waste
// time resolving nodes that will not be returned anyway
$resultFileIds = $this->slice($resultFileIds, $report);

// find sabre nodes by file id, restricted to the root node path
$results = $this->findNodesByFileIds($reportTargetNode, $resultFileIds);
}

if (!is_null($report->limit)) {
$length = $report->limit['size'];
$offset = $report->limit['page'] * $length;
$results = array_slice($results, $offset, $length);
}

$filesUri = $this->getFilesBaseUri($uri, $reportTargetNode->getPath());
$results = $this->prepareResponses($filesUri, $requestedProps, $results);

Expand All @@ -212,6 +211,15 @@ public function onReport($reportName, $report, $uri) {
return false;
}

private function slice($results, $report) {
if (!is_null($report->search)) {
$length = $report->search['limit'];
$offset = $report->search['offset'];
$results = array_slice($results, $offset, $length);
}
return $results;
}

/**
* Returns the base uri of the files root by removing
* the subpath from the URI
Expand Down
19 changes: 11 additions & 8 deletions apps/dav/lib/Files/Xml/FilterRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class FilterRequest implements XmlDeserializable {
/**
* @var array
*/
public $limit;
public $search;

/**
* The deserialize method is called during xml parsing.
Expand All @@ -51,7 +51,7 @@ static function xmlDeserialize(Reader $reader) {
$elems = (array)$reader->parseInnerTree([
'{DAV:}prop' => KeyValue::class,
'{http://owncloud.org/ns}filter-rules' => Base::class,
'{http://owncloud.org/ns}limit' => Base::class
'{http://owncloud.org/ns}search' => KeyValue::class,
]);

$newProps = [
Expand All @@ -60,7 +60,7 @@ static function xmlDeserialize(Reader $reader) {
'favorite' => null
],
'properties' => [],
'limit' => null,
'search' => null,
];

if (!is_array($elems)) {
Expand All @@ -85,13 +85,16 @@ static function xmlDeserialize(Reader $reader) {
}
}
break;
case '{http://owncloud.org/ns}limit' :
// TODO verify page and size
$newProps['limit'] = $elem['attributes'];
case '{http://owncloud.org/ns}search' :
$value = $elem['value'];
if (isset($value['{http://owncloud.org/ns}limit'])) {
$newProps['search']['limit'] = (int)$value['{http://owncloud.org/ns}limit'];
}
if (isset($value['{http://owncloud.org/ns}offset'])) {
$newProps['search']['offset'] = (int)$value['{http://owncloud.org/ns}offset'];
}
break;

}

}

$obj = new self();
Expand Down
Loading

0 comments on commit 099a9f9

Please sign in to comment.