44
44
*
45
45
*/
46
46
use bantu \IniGetWrapper \IniGetWrapper ;
47
+ use OC \Files \Filesystem ;
47
48
use OCP \Files \Mount \IMountPoint ;
49
+ use OCP \ICacheFactory ;
48
50
use OCP \IUser ;
49
51
use Symfony \Component \Process \ExecutableFinder ;
50
52
@@ -486,9 +488,20 @@ public static function findBinaryPath($program) {
486
488
* @throws \OCP\Files\NotFoundException
487
489
*/
488
490
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
+
489
495
// return storage info without adding mount points
490
496
$ includeExtStorage = \OC ::$ server ->getSystemConfig ()->getValue ('quota_include_external_storage ' , false );
491
497
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
+
492
505
if (!$ rootInfo ) {
493
506
$ rootInfo = \OC \Files \Filesystem::getFileInfo ($ path , $ includeExtStorage ? 'ext ' : false );
494
507
}
@@ -559,7 +572,7 @@ public static function getStorageInfo($path, $rootInfo = null, $includeMountPoin
559
572
[,,,$ mountPoint ] = explode ('/ ' , $ mount ->getMountPoint (), 4 );
560
573
}
561
574
562
- return [
575
+ $ info = [
563
576
'free ' => $ free ,
564
577
'used ' => $ used ,
565
578
'quota ' => $ quota ,
@@ -570,6 +583,10 @@ public static function getStorageInfo($path, $rootInfo = null, $includeMountPoin
570
583
'mountType ' => $ mount ->getMountType (),
571
584
'mountPoint ' => trim ($ mountPoint , '/ ' ),
572
585
];
586
+
587
+ $ memcache ->set ($ cacheKey , $ info , 5 * 60 );
588
+
589
+ return $ info ;
573
590
}
574
591
575
592
/**
0 commit comments