aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2017-09-06 10:16:01 +0200
committerGitHub <noreply@github.com>2017-09-06 10:16:01 +0200
commit1724fed8c530b0620aa97266b70d236fd8f38102 (patch)
tree1dd0e61d68dacc6146aeccfb13c741457f6019c1 /apps/dav
parent9d930210eec9e30bbc1fcd3e154d65eb0fc7ae28 (diff)
parent42915b1e8bea013153834ff5ec4aa57b7b2908a9 (diff)
downloadnextcloud-server-1724fed8c530b0620aa97266b70d236fd8f38102.tar.gz
nextcloud-server-1724fed8c530b0620aa97266b70d236fd8f38102.zip
Merge pull request #5415 from nextcloud/search-cache-node
cache nodes from search results
Diffstat (limited to 'apps/dav')
-rw-r--r--apps/dav/lib/Connector/Sabre/CachingTree.php39
-rw-r--r--apps/dav/lib/Connector/Sabre/ObjectTree.php6
-rw-r--r--apps/dav/lib/Connector/Sabre/Server.php1
-rw-r--r--apps/dav/lib/Files/FileSearchBackend.php15
-rw-r--r--apps/dav/lib/Server.php3
-rw-r--r--apps/dav/tests/unit/Files/FileSearchBackendTest.php6
6 files changed, 55 insertions, 15 deletions
diff --git a/apps/dav/lib/Connector/Sabre/CachingTree.php b/apps/dav/lib/Connector/Sabre/CachingTree.php
new file mode 100644
index 00000000000..80c8311fed3
--- /dev/null
+++ b/apps/dav/lib/Connector/Sabre/CachingTree.php
@@ -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;
+ }
+}
diff --git a/apps/dav/lib/Connector/Sabre/ObjectTree.php b/apps/dav/lib/Connector/Sabre/ObjectTree.php
index 3371c655f29..a44b25c24cb 100644
--- a/apps/dav/lib/Connector/Sabre/ObjectTree.php
+++ b/apps/dav/lib/Connector/Sabre/ObjectTree.php
@@ -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
*
diff --git a/apps/dav/lib/Connector/Sabre/Server.php b/apps/dav/lib/Connector/Sabre/Server.php
index 9915ffdba03..686b0ea7604 100644
--- a/apps/dav/lib/Connector/Sabre/Server.php
+++ b/apps/dav/lib/Connector/Sabre/Server.php
@@ -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
diff --git a/apps/dav/lib/Files/FileSearchBackend.php b/apps/dav/lib/Files/FileSearchBackend.php
index 0d837807fd8..515e7ed0121 100644
--- a/apps/dav/lib/Files/FileSearchBackend.php
+++ b/apps/dav/lib/Files/FileSearchBackend.php
@@ -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);
}
diff --git a/apps/dav/lib/Server.php b/apps/dav/lib/Server.php
index 896af09f1c0..b93f3e6390a 100644
--- a/apps/dav/lib/Server.php
+++ b/apps/dav/lib/Server.php
@@ -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()));
diff --git a/apps/dav/tests/unit/Files/FileSearchBackendTest.php b/apps/dav/tests/unit/Files/FileSearchBackendTest.php
index 7de92c59763..28b6f082712 100644
--- a/apps/dav/tests/unit/Files/FileSearchBackendTest.php
+++ b/apps/dav/tests/unit/Files/FileSearchBackendTest.php
@@ -24,6 +24,7 @@ namespace OCA\DAV\Tests\Files;
use OC\Files\Search\SearchComparison;
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\File;
use OCA\DAV\Connector\Sabre\FilesPlugin;
@@ -34,7 +35,6 @@ use OCP\Files\IRootFolder;
use OCP\Files\Search\ISearchComparison;
use OCP\IUser;
use OCP\Share\IManager;
-use Sabre\DAV\Tree;
use SearchDAV\XML\BasicSearch;
use SearchDAV\XML\Literal;
use SearchDAV\XML\Operator;
@@ -42,7 +42,7 @@ use SearchDAV\XML\Scope;
use Test\TestCase;
class FileSearchBackendTest extends TestCase {
- /** @var Tree|\PHPUnit_Framework_MockObject_MockObject */
+ /** @var CachingTree|\PHPUnit_Framework_MockObject_MockObject */
private $tree;
/** @var IUser */
@@ -74,7 +74,7 @@ class FileSearchBackendTest extends TestCase {
->method('getUID')
->willReturn('test');
- $this->tree = $this->getMockBuilder(Tree::class)
+ $this->tree = $this->getMockBuilder(CachingTree::class)
->disableOriginalConstructor()
->getMock();