cache nodes from search results
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
ca490bafb9
commit
37e8b698f7
5 changed files with 52 additions and 12 deletions
39
apps/dav/lib/Connector/Sabre/CachingTree.php
Normal file
39
apps/dav/lib/Connector/Sabre/CachingTree.php
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2017 Robin Appelman <robin@icewind.nl>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\DAV\Connector\Sabre;
|
||||
|
||||
use Sabre\DAV\Tree;
|
||||
|
||||
class CachingTree extends Tree {
|
||||
/**
|
||||
* Store a node in the cache
|
||||
*
|
||||
* @param Node $node
|
||||
* @param null|string $path
|
||||
*/
|
||||
public function cacheNode(Node $node, $path = null) {
|
||||
if (is_null($path)) {
|
||||
$path = $node->getPath();
|
||||
}
|
||||
$this->cache[trim($path, '/')] = $node;
|
||||
}
|
||||
}
|
|
@ -39,7 +39,7 @@ use OCP\Files\StorageInvalidException;
|
|||
use OCP\Files\StorageNotAvailableException;
|
||||
use OCP\Lock\LockedException;
|
||||
|
||||
class ObjectTree extends \Sabre\DAV\Tree {
|
||||
class ObjectTree extends CachingTree {
|
||||
|
||||
/**
|
||||
* @var \OC\Files\View
|
||||
|
@ -97,10 +97,6 @@ class ObjectTree extends \Sabre\DAV\Tree {
|
|||
return $path;
|
||||
}
|
||||
|
||||
public function cacheNode(Node $node) {
|
||||
$this->cache[trim($node->getPath(), '/')] = $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the INode object for the requested path
|
||||
*
|
||||
|
|
|
@ -33,6 +33,7 @@ namespace OCA\DAV\Connector\Sabre;
|
|||
* @see \Sabre\DAV\Server
|
||||
*/
|
||||
class Server extends \Sabre\DAV\Server {
|
||||
/** @var CachingTree $tree */
|
||||
|
||||
/**
|
||||
* @see \Sabre\DAV\Server
|
||||
|
|
|
@ -26,6 +26,7 @@ use OC\Files\Search\SearchComparison;
|
|||
use OC\Files\Search\SearchOrder;
|
||||
use OC\Files\Search\SearchQuery;
|
||||
use OC\Files\View;
|
||||
use OCA\DAV\Connector\Sabre\CachingTree;
|
||||
use OCA\DAV\Connector\Sabre\Directory;
|
||||
use OCA\DAV\Connector\Sabre\FilesPlugin;
|
||||
use OCA\DAV\Connector\Sabre\TagsPlugin;
|
||||
|
@ -39,7 +40,6 @@ use OCP\Files\Search\ISearchQuery;
|
|||
use OCP\IUser;
|
||||
use OCP\Share\IManager;
|
||||
use Sabre\DAV\Exception\NotFound;
|
||||
use Sabre\DAV\Tree;
|
||||
use SearchDAV\Backend\ISearchBackend;
|
||||
use SearchDAV\Backend\SearchPropertyDefinition;
|
||||
use SearchDAV\Backend\SearchResult;
|
||||
|
@ -49,7 +49,7 @@ use SearchDAV\XML\Operator;
|
|||
use SearchDAV\XML\Order;
|
||||
|
||||
class FileSearchBackend implements ISearchBackend {
|
||||
/** @var Tree */
|
||||
/** @var CachingTree */
|
||||
private $tree;
|
||||
|
||||
/** @var IUser */
|
||||
|
@ -67,14 +67,14 @@ class FileSearchBackend implements ISearchBackend {
|
|||
/**
|
||||
* FileSearchBackend constructor.
|
||||
*
|
||||
* @param Tree $tree
|
||||
* @param CachingTree $tree
|
||||
* @param IUser $user
|
||||
* @param IRootFolder $rootFolder
|
||||
* @param IManager $shareManager
|
||||
* @param View $view
|
||||
* @internal param IRootFolder $rootFolder
|
||||
*/
|
||||
public function __construct(Tree $tree, IUser $user, IRootFolder $rootFolder, IManager $shareManager, View $view) {
|
||||
public function __construct(CachingTree $tree, IUser $user, IRootFolder $rootFolder, IManager $shareManager, View $view) {
|
||||
$this->tree = $tree;
|
||||
$this->user = $user;
|
||||
$this->rootFolder = $rootFolder;
|
||||
|
@ -157,10 +157,13 @@ class FileSearchBackend implements ISearchBackend {
|
|||
|
||||
return array_map(function (Node $node) {
|
||||
if ($node instanceof Folder) {
|
||||
return new SearchResult(new \OCA\DAV\Connector\Sabre\Directory($this->view, $node, $this->tree, $this->shareManager), $this->getHrefForNode($node));
|
||||
$davNode = new \OCA\DAV\Connector\Sabre\Directory($this->view, $node, $this->tree, $this->shareManager);
|
||||
} else {
|
||||
return new SearchResult(new \OCA\DAV\Connector\Sabre\File($this->view, $node, $this->shareManager), $this->getHrefForNode($node));
|
||||
$davNode = new \OCA\DAV\Connector\Sabre\File($this->view, $node, $this->shareManager);
|
||||
}
|
||||
$path = $this->getHrefForNode($node);
|
||||
$this->tree->cacheNode($davNode, $path);
|
||||
return new SearchResult($davNode, $path);
|
||||
}, $results);
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ use OCA\DAV\Comments\CommentsPlugin;
|
|||
use OCA\DAV\Connector\Sabre\Auth;
|
||||
use OCA\DAV\Connector\Sabre\BearerAuth;
|
||||
use OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin;
|
||||
use OCA\DAV\Connector\Sabre\CachingTree;
|
||||
use OCA\DAV\Connector\Sabre\CommentPropertiesPlugin;
|
||||
use OCA\DAV\Connector\Sabre\CopyEtagHeaderPlugin;
|
||||
use OCA\DAV\Connector\Sabre\DavAclPlugin;
|
||||
|
@ -75,7 +76,7 @@ class Server {
|
|||
$dispatcher = \OC::$server->getEventDispatcher();
|
||||
|
||||
$root = new RootCollection();
|
||||
$this->server = new \OCA\DAV\Connector\Sabre\Server($root);
|
||||
$this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root));
|
||||
|
||||
// Add maintenance plugin
|
||||
$this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig()));
|
||||
|
|
Loading…
Reference in a new issue