From 7c4d9add0d98091d8dc932553f84f9c00a906389 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 25 Aug 2016 15:48:53 +0200 Subject: reuse the userfolder's fileinfo when possible during dav setup --- apps/dav/lib/Connector/Sabre/ServerFactory.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/dav/lib/Connector/Sabre/ServerFactory.php b/apps/dav/lib/Connector/Sabre/ServerFactory.php index 55b967619d6..644f0f28f57 100644 --- a/apps/dav/lib/Connector/Sabre/ServerFactory.php +++ b/apps/dav/lib/Connector/Sabre/ServerFactory.php @@ -29,6 +29,7 @@ namespace OCA\DAV\Connector\Sabre; +use OC\Files\Node\Folder; use OCA\DAV\Files\BrowserErrorPagePlugin; use OCP\Files\Mount\IMountManager; use OCP\IConfig; @@ -135,7 +136,11 @@ class ServerFactory { /** @var \OC\Files\View $view */ $view = $viewCallBack($server); - $rootInfo = $view->getFileInfo(''); + if ($userFolder instanceof Folder && $userFolder->getPath() === $view->getRoot()) { + $rootInfo = $userFolder; + } else { + $rootInfo = $view->getFileInfo(''); + } // Create ownCloud Dir if ($rootInfo->getType() === 'dir') { -- cgit v1.2.3 From b2d365734a692c6e09a07d0190fdabf64f3a295a Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 25 Aug 2016 15:49:18 +0200 Subject: cache root id in mountpoint --- lib/private/Files/Mount/MountPoint.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/private/Files/Mount/MountPoint.php b/lib/private/Files/Mount/MountPoint.php index 4aef340149c..42b79596c98 100644 --- a/lib/private/Files/Mount/MountPoint.php +++ b/lib/private/Files/Mount/MountPoint.php @@ -41,6 +41,7 @@ class MountPoint implements IMountPoint { protected $storage = null; protected $class; protected $storageId; + protected $rootId = null; /** * Configuration options for the storage backend @@ -264,7 +265,10 @@ class MountPoint implements IMountPoint { * @return int */ public function getStorageRootId() { - return (int)$this->getStorage()->getCache()->getId(''); + if (is_null($this->rootId)) { + $this->rootId = (int)$this->getStorage()->getCache()->getId(''); + } + return $this->rootId; } public function getMountId() { -- cgit v1.2.3 From 2693ae870eff6a6aec769c035c200f0b5caf4e6f Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 25 Aug 2016 15:49:36 +0200 Subject: cache user folders --- lib/private/Files/Node/Root.php | 42 +++++++++++++++++++++++++---------------- lib/private/legacy/util.php | 1 + tests/lib/TestCase.php | 1 + 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/lib/private/Files/Node/Root.php b/lib/private/Files/Node/Root.php index bad865a7987..e5921206a39 100644 --- a/lib/private/Files/Node/Root.php +++ b/lib/private/Files/Node/Root.php @@ -28,6 +28,7 @@ namespace OC\Files\Node; +use OC\Cache\CappedMemoryCache; use OC\Files\Mount\Manager; use OC\Files\Mount\MountPoint; use OCP\Files\NotFoundException; @@ -71,6 +72,8 @@ class Root extends Folder implements IRootFolder { */ private $user; + private $userFolderCache; + /** * @param \OC\Files\Mount\Manager $manager * @param \OC\Files\View $view @@ -81,6 +84,7 @@ class Root extends Folder implements IRootFolder { $this->mountManager = $manager; $this->user = $user; $this->emitter = new PublicEmitter(); + $this->userFolderCache = new CappedMemoryCache(); } /** @@ -335,25 +339,31 @@ class Root extends Folder implements IRootFolder { * @return \OCP\Files\Folder */ public function getUserFolder($userId) { - \OC\Files\Filesystem::initMountPoints($userId); - $dir = '/' . $userId; - $folder = null; - - try { - $folder = $this->get($dir); - } catch (NotFoundException $e) { - $folder = $this->newFolder($dir); - } + if (!$this->userFolderCache->hasKey($userId)) { + \OC\Files\Filesystem::initMountPoints($userId); + $dir = '/' . $userId; + $folder = null; + + try { + $folder = $this->get($dir); + } catch (NotFoundException $e) { + $folder = $this->newFolder($dir); + } - $dir = '/files'; - try { - $folder = $folder->get($dir); - } catch (NotFoundException $e) { - $folder = $folder->newFolder($dir); - \OC_Util::copySkeleton($userId, $folder); + $dir = '/files'; + try { + $folder = $folder->get($dir); + } catch (NotFoundException $e) { + $folder = $folder->newFolder($dir); + \OC_Util::copySkeleton($userId, $folder); + } + $this->userFolderCache->set($userId, $folder); } - return $folder; + return $this->userFolderCache->get($userId); + } + public function clearCache() { + $this->userFolderCache = new CappedMemoryCache(); } } diff --git a/lib/private/legacy/util.php b/lib/private/legacy/util.php index a975da39271..73c0e2249cb 100644 --- a/lib/private/legacy/util.php +++ b/lib/private/legacy/util.php @@ -356,6 +356,7 @@ class OC_Util { */ public static function tearDownFS() { \OC\Files\Filesystem::tearDown(); + \OC::$server->getRootFolder()->clearCache(); self::$fsSetup = false; self::$rootMounted = false; } diff --git a/tests/lib/TestCase.php b/tests/lib/TestCase.php index 514cb6ea3a5..b9b18c644fd 100644 --- a/tests/lib/TestCase.php +++ b/tests/lib/TestCase.php @@ -24,6 +24,7 @@ namespace Test; use DOMDocument; use DOMNode; +use OC\Cache\CappedMemoryCache; use OC\Command\QueueBus; use OC\Files\Filesystem; use OC\Template\Base; -- cgit v1.2.3 From fb88d668575562407edcaf392ec6f771cba55dba Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 25 Aug 2016 15:50:02 +0200 Subject: optimize getUserFolder for the common case --- lib/private/Files/Node/Root.php | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/private/Files/Node/Root.php b/lib/private/Files/Node/Root.php index e5921206a39..007847fb513 100644 --- a/lib/private/Files/Node/Root.php +++ b/lib/private/Files/Node/Root.php @@ -341,22 +341,17 @@ class Root extends Folder implements IRootFolder { public function getUserFolder($userId) { if (!$this->userFolderCache->hasKey($userId)) { \OC\Files\Filesystem::initMountPoints($userId); - $dir = '/' . $userId; - $folder = null; try { - $folder = $this->get($dir); + $folder = $this->get('/' . $userId . '/files'); } catch (NotFoundException $e) { - $folder = $this->newFolder($dir); - } - - $dir = '/files'; - try { - $folder = $folder->get($dir); - } catch (NotFoundException $e) { - $folder = $folder->newFolder($dir); + if (!$this->nodeExists('/' . $userId)) { + $this->newFolder('/' . $userId); + } + $folder = $this->newFolder('/' . $userId . '/files'); \OC_Util::copySkeleton($userId, $folder); } + $this->userFolderCache->set($userId, $folder); } -- cgit v1.2.3