Merge pull request #12 from CarlSchwan/feat/allow-preloading

Allow preloading of properties in one go
This commit is contained in:
Robin Appelman 2022-04-08 15:01:51 +00:00 committed by GitHub
commit 7bf414d47a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View file

@ -21,6 +21,7 @@
namespace SearchDAV\Backend;
use Sabre\DAV\INode;
use SearchDAV\Query\Query;
interface ISearchBackend {
@ -81,4 +82,10 @@ interface ISearchBackend {
* @return SearchResult[]
*/
public function search(Query $query);
/**
* @param INode[] $nodes
* @param string[] $requestProperties
*/
public function preloadPropertyFor(array $nodes, array $requestProperties): void;
}

View file

@ -22,6 +22,7 @@
namespace SearchDAV\DAV;
use Sabre\DAV\Exception\BadRequest;
use Sabre\DAV\INode;
use Sabre\DAV\PropFind;
use Sabre\DAV\Server;
use Sabre\HTTP\ResponseInterface;
@ -170,6 +171,10 @@ class SearchHandler {
private function getPropertiesIteratorResults($results, $propertyNames = [], $depth = 0): \Iterator {
$propFindType = $propertyNames ? PropFind::NORMAL : PropFind::ALLPROPS;
$this->searchBackend->preloadPropertyFor(array_map(function (SearchResult $result): INode {
return $result->node;
}, $results), $propertyNames);
foreach ($results as $result) {
$node = $result->node;
$propFind = new PropFind($result->href, (array)$propertyNames, $depth, $propFindType);