diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2016-08-27 22:44:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-27 22:44:29 +0200 |
commit | 4d85ffc27cab959b25c00426e334319495535bb9 (patch) | |
tree | 690e50739a02d69dd8fd5d994f88670524dde427 /lib/private/Files | |
parent | ccbbf61ed60dcff59208c756b0d77b6157925ac7 (diff) | |
parent | fb88d668575562407edcaf392ec6f771cba55dba (diff) | |
download | nextcloud-server-4d85ffc27cab959b25c00426e334319495535bb9.tar.gz nextcloud-server-4d85ffc27cab959b25c00426e334319495535bb9.zip |
Merge pull request #1054 from nextcloud/less-cache-hits
Reduce the number of cache operations for dav operations
Diffstat (limited to 'lib/private/Files')
-rw-r--r-- | lib/private/Files/Mount/MountPoint.php | 6 | ||||
-rw-r--r-- | lib/private/Files/Node/Root.php | 37 |
2 files changed, 26 insertions, 17 deletions
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() { diff --git a/lib/private/Files/Node/Root.php b/lib/private/Files/Node/Root.php index bad865a7987..007847fb513 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,26 @@ 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); + + try { + $folder = $this->get('/' . $userId . '/files'); + } catch (NotFoundException $e) { + if (!$this->nodeExists('/' . $userId)) { + $this->newFolder('/' . $userId); + } + $folder = $this->newFolder('/' . $userId . '/files'); + \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(); } } |