Merge pull request #21401 from owncloud/dav-cache-getchildren

Put nodes from Directory->getChildren in the ObjectTree cache
This commit is contained in:
Thomas Müller 2016-01-25 10:02:32 +01:00
commit 9d36972e0f
3 changed files with 32 additions and 7 deletions

View File

@ -53,6 +53,23 @@ class Directory extends \OCA\DAV\Connector\Sabre\Node
*/ */
private $quotaInfo; private $quotaInfo;
/**
* @var ObjectTree|null
*/
private $tree;
/**
* Sets up the node, expects a full path name
*
* @param \OC\Files\View $view
* @param \OCP\Files\FileInfo $info
* @param ObjectTree|null $tree
*/
public function __construct($view, $info, $tree = null) {
parent::__construct($view, $info);
$this->tree = $tree;
}
/** /**
* Creates a new file in the directory * Creates a new file in the directory
* *
@ -185,10 +202,13 @@ class Directory extends \OCA\DAV\Connector\Sabre\Node
} }
if ($info['mimetype'] == 'httpd/unix-directory') { if ($info['mimetype'] == 'httpd/unix-directory') {
$node = new \OCA\DAV\Connector\Sabre\Directory($this->fileView, $info); $node = new \OCA\DAV\Connector\Sabre\Directory($this->fileView, $info, $this->tree);
} else { } else {
$node = new \OCA\DAV\Connector\Sabre\File($this->fileView, $info); $node = new \OCA\DAV\Connector\Sabre\File($this->fileView, $info);
} }
if ($this->tree) {
$this->tree->cacheNode($node);
}
return $node; return $node;
} }

View File

@ -94,6 +94,10 @@ class ObjectTree extends \Sabre\DAV\Tree {
return $path; return $path;
} }
public function cacheNode(Node $node) {
$this->cache[trim($node->getPath(), '/')] = $node;
}
/** /**
* Returns the INode object for the requested path * Returns the INode object for the requested path
* *
@ -108,6 +112,11 @@ class ObjectTree extends \Sabre\DAV\Tree {
} }
$path = trim($path, '/'); $path = trim($path, '/');
if (isset($this->cache[$path])) {
return $this->cache[$path];
}
if ($path) { if ($path) {
try { try {
$this->fileView->verifyPath($path, basename($path)); $this->fileView->verifyPath($path, basename($path));
@ -116,10 +125,6 @@ class ObjectTree extends \Sabre\DAV\Tree {
} }
} }
if (isset($this->cache[$path])) {
return $this->cache[$path];
}
// Is it the root node? // Is it the root node?
if (!strlen($path)) { if (!strlen($path)) {
return $this->rootNode; return $this->rootNode;
@ -162,7 +167,7 @@ class ObjectTree extends \Sabre\DAV\Tree {
} }
if ($info->getType() === 'dir') { if ($info->getType() === 'dir') {
$node = new \OCA\DAV\Connector\Sabre\Directory($this->fileView, $info); $node = new \OCA\DAV\Connector\Sabre\Directory($this->fileView, $info, $this);
} else { } else {
$node = new \OCA\DAV\Connector\Sabre\File($this->fileView, $info); $node = new \OCA\DAV\Connector\Sabre\File($this->fileView, $info);
} }

View File

@ -120,7 +120,7 @@ class ServerFactory {
// Create ownCloud Dir // Create ownCloud Dir
if ($rootInfo->getType() === 'dir') { if ($rootInfo->getType() === 'dir') {
$root = new \OCA\DAV\Connector\Sabre\Directory($view, $rootInfo); $root = new \OCA\DAV\Connector\Sabre\Directory($view, $rootInfo, $objectTree);
} else { } else {
$root = new \OCA\DAV\Connector\Sabre\File($view, $rootInfo); $root = new \OCA\DAV\Connector\Sabre\File($view, $rootInfo);
} }