Skip to content

Commit 3f55108

Browse files
authored
Merge pull request #32048 from nextcloud/cache-storage-info
cache storage info in memcache for 5m
2 parents 9a1a14d + bdfef2d commit 3f55108

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

lib/private/legacy/OC_Helper.php

+18-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@
4444
*
4545
*/
4646
use bantu\IniGetWrapper\IniGetWrapper;
47+
use OC\Files\Filesystem;
4748
use OCP\Files\Mount\IMountPoint;
49+
use OCP\ICacheFactory;
4850
use OCP\IUser;
4951
use Symfony\Component\Process\ExecutableFinder;
5052

@@ -486,9 +488,20 @@ public static function findBinaryPath($program) {
486488
* @throws \OCP\Files\NotFoundException
487489
*/
488490
public static function getStorageInfo($path, $rootInfo = null, $includeMountPoints = true) {
491+
/** @var ICacheFactory $cacheFactory */
492+
$cacheFactory = \OC::$server->get(ICacheFactory::class);
493+
$memcache = $cacheFactory->createLocal('storage_info');
494+
489495
// return storage info without adding mount points
490496
$includeExtStorage = \OC::$server->getSystemConfig()->getValue('quota_include_external_storage', false);
491497

498+
$fullPath = Filesystem::getView()->getAbsolutePath($path);
499+
$cacheKey = $fullPath. '::' . ($includeMountPoints ? 'include' : 'exclude');
500+
$cached = $memcache->get($cacheKey);
501+
if ($cached) {
502+
return $cached;
503+
}
504+
492505
if (!$rootInfo) {
493506
$rootInfo = \OC\Files\Filesystem::getFileInfo($path, $includeExtStorage ? 'ext' : false);
494507
}
@@ -559,7 +572,7 @@ public static function getStorageInfo($path, $rootInfo = null, $includeMountPoin
559572
[,,,$mountPoint] = explode('/', $mount->getMountPoint(), 4);
560573
}
561574

562-
return [
575+
$info = [
563576
'free' => $free,
564577
'used' => $used,
565578
'quota' => $quota,
@@ -570,6 +583,10 @@ public static function getStorageInfo($path, $rootInfo = null, $includeMountPoin
570583
'mountType' => $mount->getMountType(),
571584
'mountPoint' => trim($mountPoint, '/'),
572585
];
586+
587+
$memcache->set($cacheKey, $info, 5 * 60);
588+
589+
return $info;
573590
}
574591

575592
/**

0 commit comments

Comments
 (0)