Skip to content

Commit

Permalink
better caching in storage stats calculations
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Aug 18, 2023
1 parent 36f9ebb commit 80b001f
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/private/legacy/OC_Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
*/
class OC_Helper {
private static $templateManager;
private static ?ICacheFactory $cacheFactory = null;
private static ?bool $quotaIncludeExternalStorage = null;

/**
* Make a human file size
Expand Down Expand Up @@ -475,12 +477,15 @@ public static function findBinaryPath(string $program): ?string {
* @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) {
Expand All @@ -497,7 +502,7 @@ public static function getStorageInfo($path, $rootInfo = null, $includeMountPoin
}

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');
Expand All @@ -512,9 +517,9 @@ public static function getStorageInfo($path, $rootInfo = null, $includeMountPoin
$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')
) {
Expand Down

0 comments on commit 80b001f

Please sign in to comment.