summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2016-04-15 14:03:48 +0200
committerRoeland Jago Douma <rullzer@owncloud.com>2016-04-19 14:04:00 +0200
commit2f1c62ce0b022a2549ff80a299b8a3b314106fae (patch)
tree9ddac98ce1f4ad51cff1bcfaa130b229665b7c31
parentc98fef8a51aa9828097db697fde2641771ed24c7 (diff)
downloadnextcloud-server-2f1c62ce0b022a2549ff80a299b8a3b314106fae.tar.gz
nextcloud-server-2f1c62ce0b022a2549ff80a299b8a3b314106fae.zip
Only construct the storage when we start using it
-rw-r--r--apps/files_sharing/lib/sharedmount.php23
-rw-r--r--lib/private/files/config/cachedmountinfo.php14
-rw-r--r--lib/private/files/config/lazystoragemountinfo.php74
-rw-r--r--lib/private/files/config/usermountcache.php11
-rw-r--r--lib/private/files/mount/mountpoint.php9
-rw-r--r--lib/public/files/mount/imountpoint.php8
6 files changed, 116 insertions, 23 deletions
diff --git a/apps/files_sharing/lib/sharedmount.php b/apps/files_sharing/lib/sharedmount.php
index 624fbce3311..4aed80b12b2 100644
--- a/apps/files_sharing/lib/sharedmount.php
+++ b/apps/files_sharing/lib/sharedmount.php
@@ -49,6 +49,9 @@ class SharedMount extends MountPoint implements MoveableMount {
*/
private $user;
+ /** @var \OCP\Share\IShare */
+ private $share;
+
/**
* @param string $storage
* @param SharedMount[] $mountpoints
@@ -58,11 +61,10 @@ class SharedMount extends MountPoint implements MoveableMount {
public function __construct($storage, array $mountpoints, $arguments = null, $loader = null) {
$this->user = $arguments['user'];
$this->recipientView = new View('/' . $this->user . '/files');
- /** @var \OCP\Share\IShare $share */
- $share = $arguments['newShare'];
- $newMountPoint = $this->verifyMountPoint($share, $mountpoints);
+ $this->share = $arguments['newShare'];
+ $newMountPoint = $this->verifyMountPoint($this->share, $mountpoints);
$absMountPoint = '/' . $this->user . '/files' . $newMountPoint;
- $arguments['ownerView'] = new View('/' . $share->getShareOwner() . '/files');
+ $arguments['ownerView'] = new View('/' . $this->share->getShareOwner() . '/files');
parent::__construct($storage, $absMountPoint, $arguments, $loader);
}
@@ -210,8 +212,15 @@ class SharedMount extends MountPoint implements MoveableMount {
* @return \OCP\Share\IShare
*/
public function getShare() {
- /** @var $storage \OC\Files\Storage\Shared */
- $storage = $this->getStorage();
- return $storage->getShare();
+ return $this->share;
+ }
+
+ /**
+ * Get the file id of the root of the storage
+ *
+ * @return int
+ */
+ public function getStorageRootId() {
+ return $this->share->getNodeId();
}
}
diff --git a/lib/private/files/config/cachedmountinfo.php b/lib/private/files/config/cachedmountinfo.php
index 2993c979a7f..ce75cb66896 100644
--- a/lib/private/files/config/cachedmountinfo.php
+++ b/lib/private/files/config/cachedmountinfo.php
@@ -30,22 +30,22 @@ class CachedMountInfo implements ICachedMountInfo {
/**
* @var IUser
*/
- private $user;
+ protected $user;
/**
* @var int
*/
- private $storageId;
+ protected $storageId;
/**
* @var int
*/
- private $rootId;
+ protected $rootId;
/**
* @var string
*/
- private $mountPoint;
+ protected $mountPoint;
/**
* CachedMountInfo constructor.
@@ -88,9 +88,9 @@ class CachedMountInfo implements ICachedMountInfo {
*/
public function getMountPointNode() {
// TODO injection etc
- Filesystem::initMountPoints($this->user->getUID());
- $userNode = \OC::$server->getUserFolder($this->user->getUID());
- $nodes = $userNode->getById($this->rootId);
+ Filesystem::initMountPoints($this->getUser()->getUID());
+ $userNode = \OC::$server->getUserFolder($this->getUser()->getUID());
+ $nodes = $userNode->getById($this->getRootId());
if (count($nodes) > 0) {
return $nodes[0];
} else {
diff --git a/lib/private/files/config/lazystoragemountinfo.php b/lib/private/files/config/lazystoragemountinfo.php
new file mode 100644
index 00000000000..654c5b2b23e
--- /dev/null
+++ b/lib/private/files/config/lazystoragemountinfo.php
@@ -0,0 +1,74 @@
+<?php
+/**
+ * @author Robin Appelman <icewind@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * 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, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OC\Files\Config;
+
+use OC\Files\Filesystem;
+use OCP\Files\Config\ICachedMountInfo;
+use OCP\Files\Mount\IMountPoint;
+use OCP\Files\Node;
+use OCP\IUser;
+
+class LazyStorageMountInfo extends CachedMountInfo {
+ /** @var IMountPoint */
+ private $mount;
+
+ /**
+ * CachedMountInfo constructor.
+ *
+ * @param IUser $user
+ * @param IMountPoint $mount
+ */
+ public function __construct(IUser $user, IMountPoint $mount) {
+ $this->user = $user;
+ $this->mount = $mount;
+ }
+
+ /**
+ * @return int the numeric storage id of the mount
+ */
+ public function getStorageId() {
+ if (!$this->storageId) {
+ $this->storageId = $this->mount->getStorage()->getStorageCache()->getNumericId();
+ }
+ return parent::getStorageId();
+ }
+
+ /**
+ * @return int the fileid of the root of the mount
+ */
+ public function getRootId() {
+ if (!$this->rootId) {
+ $this->rootId = $this->mount->getStorageRootId();
+ }
+ return parent::getRootId();
+ }
+
+ /**
+ * @return string the mount point of the mount for the user
+ */
+ public function getMountPoint() {
+ if (!$this->mountPoint) {
+ $this->mountPoint = $this->mount->getMountPoint();
+ }
+ return parent::getMountPoint();
+ }
+}
diff --git a/lib/private/files/config/usermountcache.php b/lib/private/files/config/usermountcache.php
index 68436174025..05ca146f4be 100644
--- a/lib/private/files/config/usermountcache.php
+++ b/lib/private/files/config/usermountcache.php
@@ -80,18 +80,11 @@ class UserMountCache implements IUserMountCache {
});
/** @var ICachedMountInfo[] $newMounts */
$newMounts = array_map(function (IMountPoint $mount) use ($user) {
- $storage = $mount->getStorage();
- if ($storage->instanceOfStorage('\OC\Files\Storage\Shared')) {
- $rootId = (int)$storage->getShare()->getNodeId();
- } else {
- $rootId = (int)$storage->getCache()->getId('');
- }
- $storageId = (int)$storage->getStorageCache()->getNumericId();
// filter out any storages which aren't scanned yet since we aren't interested in files from those storages (yet)
- if ($rootId === -1) {
+ if ($mount->getStorageRootId() === -1) {
return null;
} else {
- return new CachedMountInfo($user, $storageId, $rootId, $mount->getMountPoint());
+ return new LazyStorageMountInfo($user, $mount);
}
}, $mounts);
$newMounts = array_values(array_filter($newMounts));
diff --git a/lib/private/files/mount/mountpoint.php b/lib/private/files/mount/mountpoint.php
index b606c625cb1..7b9294fc1e0 100644
--- a/lib/private/files/mount/mountpoint.php
+++ b/lib/private/files/mount/mountpoint.php
@@ -239,4 +239,13 @@ class MountPoint implements IMountPoint {
public function getOptions() {
return $this->mountOptions;
}
+
+ /**
+ * Get the file id of the root of the storage
+ *
+ * @return int
+ */
+ public function getStorageRootId() {
+ return (int)$this->getStorage()->getCache()->getId('');
+ }
}
diff --git a/lib/public/files/mount/imountpoint.php b/lib/public/files/mount/imountpoint.php
index 9ce1396c1d1..bc7bf81709f 100644
--- a/lib/public/files/mount/imountpoint.php
+++ b/lib/public/files/mount/imountpoint.php
@@ -94,4 +94,12 @@ interface IMountPoint {
* @since 8.1.0
*/
public function getOptions();
+
+ /**
+ * Get the file id of the root of the storage
+ *
+ * @return int
+ * @since 9.1.0
+ */
+ public function getStorageRootId();
}