diff options
author | Morris Jobke <hey@morrisjobke.de> | 2016-09-08 21:09:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-08 21:09:14 +0200 |
commit | 5ac26d12f0a771bcaf8a44acdb469b68daebc446 (patch) | |
tree | 0393b11ecdfa483f287f6137a119bd67c32e6783 /apps | |
parent | e18fecae472ef9a9da0be724849285891d855b67 (diff) | |
parent | e8e950a4d2972a4950e00a67cc8c1f0447701986 (diff) | |
download | nextcloud-server-5ac26d12f0a771bcaf8a44acdb469b68daebc446.tar.gz nextcloud-server-5ac26d12f0a771bcaf8a44acdb469b68daebc446.zip |
Merge pull request #1247 from nextcloud/storage-id-global-cache
more efficient querying of numeric storage ids
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files_external/lib/Config/ConfigAdapter.php | 55 | ||||
-rw-r--r-- | apps/files_sharing/tests/TestCase.php | 1 |
2 files changed, 33 insertions, 23 deletions
diff --git a/apps/files_external/lib/Config/ConfigAdapter.php b/apps/files_external/lib/Config/ConfigAdapter.php index 5d8e30b6da6..efeb3d75586 100644 --- a/apps/files_external/lib/Config/ConfigAdapter.php +++ b/apps/files_external/lib/Config/ConfigAdapter.php @@ -121,54 +121,63 @@ class ConfigAdapter implements IMountProvider { public function getMountsForUser(IUser $user, IStorageFactory $loader) { $this->migrator->migrateUser($user); - $mounts = []; - $this->userStoragesService->setUser($user); $this->userGlobalStoragesService->setUser($user); - foreach ($this->userGlobalStoragesService->getAllStoragesForUser() as $storage) { + $storageConfigs = $this->userGlobalStoragesService->getAllStoragesForUser(); + + $storages = array_map(function(StorageConfig $storageConfig) use ($user) { try { - $this->prepareStorageConfig($storage, $user); - $impl = $this->constructStorage($storage); + $this->prepareStorageConfig($storageConfig, $user); + return $this->constructStorage($storageConfig); } catch (\Exception $e) { // propagate exception into filesystem - $impl = new FailedStorage(['exception' => $e]); + return new FailedStorage(['exception' => $e]); } + }, $storageConfigs); + + \OC\Files\Cache\Storage::getGlobalCache()->loadForStorageIds(array_map(function(Storage\IStorage $storage) { + return $storage->getId(); + }, $storages)); + + $availableStorages = array_map(function (Storage\IStorage $storage, StorageConfig $storageConfig) { try { - $availability = $impl->getAvailability(); + $availability = $storage->getAvailability(); if (!$availability['available'] && !Availability::shouldRecheck($availability)) { - $impl = new FailedStorage([ - 'exception' => new StorageNotAvailableException('Storage with mount id ' . $storage->getId() . ' is not available') + $storage = new FailedStorage([ + 'exception' => new StorageNotAvailableException('Storage with mount id ' . $storageConfig->getId() . ' is not available') ]); } } catch (\Exception $e) { // propagate exception into filesystem - $impl = new FailedStorage(['exception' => $e]); + $storage = new FailedStorage(['exception' => $e]); } + return $storage; + }, $storages, $storageConfigs); - if ($storage->getType() === StorageConfig::MOUNT_TYPE_PERSONAl) { - $mount = new PersonalMount( + $mounts = array_map(function(StorageConfig $storageConfig, Storage\IStorage $storage) use ($user, $loader) { + if ($storageConfig->getType() === StorageConfig::MOUNT_TYPE_PERSONAl) { + return new PersonalMount( $this->userStoragesService, - $storage->getId(), - $impl, - '/' . $user->getUID() . '/files' . $storage->getMountPoint(), + $storageConfig->getId(), + $storage, + '/' . $user->getUID() . '/files' . $storageConfig->getMountPoint(), null, $loader, - $storage->getMountOptions() + $storageConfig->getMountOptions() ); } else { - $mount = new MountPoint( - $impl, - '/' . $user->getUID() . '/files' . $storage->getMountPoint(), + return new MountPoint( + $storage, + '/' . $user->getUID() . '/files' . $storageConfig->getMountPoint(), null, $loader, - $storage->getMountOptions(), - $storage->getId() + $storageConfig->getMountOptions(), + $storageConfig->getId() ); } - $mounts[$storage->getMountPoint()] = $mount; - } + }, $storageConfigs, $availableStorages); $this->userStoragesService->resetUser(); $this->userGlobalStoragesService->resetUser(); diff --git a/apps/files_sharing/tests/TestCase.php b/apps/files_sharing/tests/TestCase.php index de7968dd3ec..0ad58151dbb 100644 --- a/apps/files_sharing/tests/TestCase.php +++ b/apps/files_sharing/tests/TestCase.php @@ -168,6 +168,7 @@ abstract class TestCase extends \Test\TestCase { self::resetStorage(); \OC_Util::tearDownFS(); + \OC\Files\Cache\Storage::getGlobalCache()->clearCache(); \OC::$server->getUserSession()->setUser(null); \OC\Files\Filesystem::tearDown(); \OC::$server->getUserSession()->login($user, $password); |