diff options
author | Robin Appelman <icewind@owncloud.com> | 2015-12-02 13:36:33 +0100 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2016-01-20 16:32:52 +0100 |
commit | 99415a9f7fa26a990848c2cb63333552c1619729 (patch) | |
tree | 903a7b9c79cc5db91c12964c4db89c1b8381a9d3 /lib | |
parent | 222e719c8760871376327c1f353fe725b430614c (diff) | |
download | nextcloud-server-99415a9f7fa26a990848c2cb63333552c1619729.tar.gz nextcloud-server-99415a9f7fa26a990848c2cb63333552c1619729.zip |
multiple minor fies
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/files/config/mountprovidercollection.php | 4 | ||||
-rw-r--r-- | lib/private/files/config/usermountcache.php | 29 | ||||
-rw-r--r-- | lib/private/files/filesystem.php | 2 | ||||
-rw-r--r-- | lib/public/files/config/icachedmountinfo.php | 2 | ||||
-rw-r--r-- | lib/public/files/config/imountprovidercollection.php | 8 | ||||
-rw-r--r-- | lib/public/files/config/iusermountcache.php | 2 |
6 files changed, 36 insertions, 11 deletions
diff --git a/lib/private/files/config/mountprovidercollection.php b/lib/private/files/config/mountprovidercollection.php index acb106f926a..499fa576fbc 100644 --- a/lib/private/files/config/mountprovidercollection.php +++ b/lib/private/files/config/mountprovidercollection.php @@ -93,11 +93,13 @@ class MountProviderCollection implements IMountProviderCollection, Emitter { * @param IUser $user * @param IMountPoint[] $mountPoints */ - public function cacheMounts(IUser $user, array $mountPoints) { + public function registerMounts(IUser $user, array $mountPoints) { $this->mountCache->registerMounts($user, $mountPoints); } /** + * Get the mount cache which can be used to search for mounts without setting up the filesystem + * * @return IUserMountCache */ public function getMountCache() { diff --git a/lib/private/files/config/usermountcache.php b/lib/private/files/config/usermountcache.php index 444c59bb603..15eefd43766 100644 --- a/lib/private/files/config/usermountcache.php +++ b/lib/private/files/config/usermountcache.php @@ -31,6 +31,9 @@ use OCP\ILogger; use OCP\IUser; use OCP\IUserManager; +/** + * Cache mounts points per user in the cache so we can easilly look them up + */ class UserMountCache implements IUserMountCache { /** * @var IDBConnection @@ -64,15 +67,16 @@ class UserMountCache implements IUserMountCache { } public function registerMounts(IUser $user, array $mounts) { + // filter out non-proper storages coming from unit tests $mounts = array_filter($mounts, function (IMountPoint $mount) { return $mount->getStorage()->getCache(); }); - $mounts = array_values($mounts); /** @var ICachedMountInfo[] $newMounts */ $newMounts = array_map(function (IMountPoint $mount) use ($user) { $storage = $mount->getStorage(); $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) { return null; } else { @@ -80,9 +84,10 @@ class UserMountCache implements IUserMountCache { } }, $mounts); $newMounts = array_values(array_filter($newMounts)); - $cachedMounts = $this->getMountsForUser($user); + $cachedMounts = $this->getMountsForUser($user); $mountDiff = function (ICachedMountInfo $mount1, ICachedMountInfo $mount2) { + // since we are only looking for mounts for a specific user comparing on root id is enough return $mount1->getRootId() - $mount2->getRootId(); }; @@ -97,7 +102,8 @@ class UserMountCache implements IUserMountCache { } foreach ($removedMounts as $mount) { $this->removeFromCache($mount); - $this->mountsForUsers[$user->getUID()] = []; + $index = array_search($mount, $this->mountsForUsers[$user->getUID()]); + unset($this->mountsForUsers[$user->getUID()][$index]); } } @@ -121,6 +127,8 @@ class UserMountCache implements IUserMountCache { $query->execute(); } catch (UniqueConstraintViolationException $e) { // seems to mainly happen in tests + // can also happen during concurrent access but we can safely ignore it + // since inserting the same data twice will still result in the correct data being inserted $this->logger->error('Duplicate entry while inserting mount'); $this->logger->logException($e); } @@ -145,14 +153,17 @@ class UserMountCache implements IUserMountCache { * @return ICachedMountInfo[] */ public function getMountsForUser(IUser $user) { - $builder = $this->connection->getQueryBuilder(); - $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point') - ->from('mounts') - ->where($builder->expr()->eq('user_id', $builder->createPositionalParameter($user->getUID()))); + if (!isset($this->mountsForUsers[$user->getUID()])) { + $builder = $this->connection->getQueryBuilder(); + $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point') + ->from('mounts') + ->where($builder->expr()->eq('user_id', $builder->createPositionalParameter($user->getUID()))); - $rows = $query->execute()->fetchAll(); + $rows = $query->execute()->fetchAll(); - return array_map([$this, 'dbRowToMountInfo'], $rows); + $this->mountsForUsers[$user->getUID()] = array_map([$this, 'dbRowToMountInfo'], $rows); + } + return $this->mountsForUsers[$user->getUID()]; } /** diff --git a/lib/private/files/filesystem.php b/lib/private/files/filesystem.php index 82177ec802d..9d4a2c0aa05 100644 --- a/lib/private/files/filesystem.php +++ b/lib/private/files/filesystem.php @@ -428,7 +428,7 @@ class Filesystem { $mounts = $mountConfigManager->getMountsForUser($userObject); array_walk($mounts, array(self::$mounts, 'addMount')); $mounts[] = $mount; - $mountConfigManager->cacheMounts($userObject, $mounts); + $mountConfigManager->registerMounts($userObject, $mounts); } self::listenForNewMountProviders($mountConfigManager, $userManager); diff --git a/lib/public/files/config/icachedmountinfo.php b/lib/public/files/config/icachedmountinfo.php index dc2eb8e0db5..a587427f1f2 100644 --- a/lib/public/files/config/icachedmountinfo.php +++ b/lib/public/files/config/icachedmountinfo.php @@ -25,6 +25,8 @@ use OCP\Files\Node; use OCP\IUser; /** + * Holds information about a mount for a user + * * @since 9.0.0 */ interface ICachedMountInfo { diff --git a/lib/public/files/config/imountprovidercollection.php b/lib/public/files/config/imountprovidercollection.php index 071a8b2bfc4..39da61812a9 100644 --- a/lib/public/files/config/imountprovidercollection.php +++ b/lib/public/files/config/imountprovidercollection.php @@ -46,4 +46,12 @@ interface IMountProviderCollection { * @since 8.0.0 */ public function registerProvider(IMountProvider $provider); + + /** + * Get the mount cache which can be used to search for mounts without setting up the filesystem + * + * @return IUserMountCache + * @since 9.0.0 + */ + public function getMountCache(); } diff --git a/lib/public/files/config/iusermountcache.php b/lib/public/files/config/iusermountcache.php index 6756df56c95..156ebbf448c 100644 --- a/lib/public/files/config/iusermountcache.php +++ b/lib/public/files/config/iusermountcache.php @@ -25,6 +25,8 @@ use OCP\Files\Mount\IMountPoint; use OCP\IUser; /** + * Cache mounts points per user in the cache so we can easily look them up + * * @since 9.0.0 */ interface IUserMountCache { |