diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2023-08-18 18:01:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-18 18:01:47 +0200 |
commit | f3a3ece9cc423634c616ce4ef1639e5e1533eded (patch) | |
tree | dd66f58e1a60061da3926983ed077a35c7c070af /lib | |
parent | b82331ed3b8d7e6726071209a2be4803fe9c4dc5 (diff) | |
parent | b6c3507aa0e9c1cd17e8030b4f105199aecb6673 (diff) | |
download | nextcloud-server-f3a3ece9cc423634c616ce4ef1639e5e1533eded.tar.gz nextcloud-server-f3a3ece9cc423634c616ce4ef1639e5e1533eded.zip |
Merge pull request #39888 from nextcloud/less-container-queries
Reduce the number of container queries
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Files/Cache/Wrapper/CacheWrapper.php | 14 | ||||
-rw-r--r-- | lib/private/Files/SetupManager.php | 5 | ||||
-rw-r--r-- | lib/private/Files/Storage/Wrapper/Quota.php | 5 | ||||
-rw-r--r-- | lib/private/legacy/OC_Helper.php | 19 |
4 files changed, 29 insertions, 14 deletions
diff --git a/lib/private/Files/Cache/Wrapper/CacheWrapper.php b/lib/private/Files/Cache/Wrapper/CacheWrapper.php index 6479ea793b0..39a78f31343 100644 --- a/lib/private/Files/Cache/Wrapper/CacheWrapper.php +++ b/lib/private/Files/Cache/Wrapper/CacheWrapper.php @@ -33,8 +33,10 @@ use OC\Files\Cache\Cache; use OC\Files\Cache\QuerySearchHelper; use OCP\Files\Cache\ICache; use OCP\Files\Cache\ICacheEntry; +use OCP\Files\IMimeTypeLoader; use OCP\Files\Search\ISearchOperator; use OCP\Files\Search\ISearchQuery; +use OCP\IDBConnection; class CacheWrapper extends Cache { /** @@ -47,9 +49,15 @@ class CacheWrapper extends Cache { */ public function __construct($cache) { $this->cache = $cache; - $this->mimetypeLoader = \OC::$server->getMimeTypeLoader(); - $this->connection = \OC::$server->getDatabaseConnection(); - $this->querySearchHelper = \OC::$server->get(QuerySearchHelper::class); + if ($cache instanceof Cache) { + $this->mimetypeLoader = $cache->mimetypeLoader; + $this->connection = $cache->connection; + $this->querySearchHelper = $cache->querySearchHelper; + } else { + $this->mimetypeLoader = \OC::$server->get(IMimeTypeLoader::class); + $this->connection = \OC::$server->get(IDBConnection::class); + $this->querySearchHelper = \OC::$server->get(QuerySearchHelper::class); + } } protected function getCache() { diff --git a/lib/private/Files/SetupManager.php b/lib/private/Files/SetupManager.php index 2198c8c60b7..b44ead003a8 100644 --- a/lib/private/Files/SetupManager.php +++ b/lib/private/Files/SetupManager.php @@ -164,7 +164,8 @@ class SetupManager { return $storage; }); - Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) { + $quotaIncludeExternal = $this->config->getSystemValue('quota_include_external_storage', false); + Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) use ($quotaIncludeExternal) { // set up quota for home storages, even for other users // which can happen when using sharing @@ -176,7 +177,7 @@ class SetupManager { $user = $storage->getUser(); return new Quota(['storage' => $storage, 'quotaCallback' => function () use ($user) { return OC_Util::getUserQuota($user); - }, 'root' => 'files']); + }, 'root' => 'files', 'include_external_storage' => $quotaIncludeExternal]); } } diff --git a/lib/private/Files/Storage/Wrapper/Quota.php b/lib/private/Files/Storage/Wrapper/Quota.php index 5786dba5114..35dbc9fcd26 100644 --- a/lib/private/Files/Storage/Wrapper/Quota.php +++ b/lib/private/Files/Storage/Wrapper/Quota.php @@ -45,6 +45,7 @@ class Quota extends Wrapper { protected int|float|null $quota; protected string $sizeRoot; private SystemConfig $config; + private bool $quotaIncludeExternalStorage; /** * @param array $parameters @@ -54,7 +55,7 @@ class Quota extends Wrapper { $this->quota = $parameters['quota'] ?? null; $this->quotaCallback = $parameters['quotaCallback'] ?? null; $this->sizeRoot = $parameters['root'] ?? ''; - $this->config = \OC::$server->get(SystemConfig::class); + $this->quotaIncludeExternalStorage = $parameters['include_external_storage'] ?? false; } /** @@ -82,7 +83,7 @@ class Quota extends Wrapper { * @return int|float */ protected function getSize($path, $storage = null) { - if ($this->config->getValue('quota_include_external_storage', false)) { + if ($this->quotaIncludeExternalStorage) { $rootInfo = Filesystem::getFileInfo('', 'ext'); if ($rootInfo) { return $rootInfo->getSize(true); diff --git a/lib/private/legacy/OC_Helper.php b/lib/private/legacy/OC_Helper.php index d96cb7bb4e9..cf39d045ae9 100644 --- a/lib/private/legacy/OC_Helper.php +++ b/lib/private/legacy/OC_Helper.php @@ -69,6 +69,8 @@ use Psr\Log\LoggerInterface; */ class OC_Helper { private static $templateManager; + private static ?ICacheFactory $cacheFactory = null; + private static ?bool $quotaIncludeExternalStorage = null; /** * Make a human file size @@ -475,12 +477,15 @@ class OC_Helper { * @throws \OCP\Files\NotFoundException */ public static function getStorageInfo($path, $rootInfo = null, $includeMountPoints = true, $useCache = true) { - /** @var ICacheFactory $cacheFactory */ - $cacheFactory = \OC::$server->get(ICacheFactory::class); - $memcache = $cacheFactory->createLocal('storage_info'); + if (!self::$cacheFactory) { + self::$cacheFactory = \OC::$server->get(ICacheFactory::class); + } + $memcache = self::$cacheFactory->createLocal('storage_info'); // return storage info without adding mount points - $includeExtStorage = \OC::$server->getSystemConfig()->getValue('quota_include_external_storage', false); + if (self::$quotaIncludeExternalStorage === null) { + self::$quotaIncludeExternalStorage = \OC::$server->getSystemConfig()->getValue('quota_include_external_storage', false); + } $view = Filesystem::getView(); if (!$view) { @@ -497,7 +502,7 @@ class OC_Helper { } if (!$rootInfo) { - $rootInfo = \OC\Files\Filesystem::getFileInfo($path, $includeExtStorage ? 'ext' : false); + $rootInfo = \OC\Files\Filesystem::getFileInfo($path, self::$quotaIncludeExternalStorage ? 'ext' : false); } if (!$rootInfo instanceof \OCP\Files\FileInfo) { throw new \OCP\Files\NotFoundException('The root directory of the user\'s files is missing'); @@ -512,9 +517,9 @@ class OC_Helper { $storage = $mount->getStorage(); $sourceStorage = $storage; if ($storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) { - $includeExtStorage = false; + self::$quotaIncludeExternalStorage = false; } - if ($includeExtStorage) { + if (self::$quotaIncludeExternalStorage) { if ($storage->instanceOfStorage('\OC\Files\Storage\Home') || $storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage') ) { |