cache the storage info for 5 min
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
5d486478d3
commit
e38a978623
|
@ -52,6 +52,7 @@ class OC_Helper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an absolute url for public use
|
* Creates an absolute url for public use
|
||||||
|
*
|
||||||
* @param string $service id
|
* @param string $service id
|
||||||
* @param bool $add_slash
|
* @param bool $add_slash
|
||||||
* @return string the url
|
* @return string the url
|
||||||
|
@ -62,13 +63,14 @@ class OC_Helper {
|
||||||
if ($service === 'files') {
|
if ($service === 'files') {
|
||||||
$url = OC::$server->getURLGenerator()->getAbsoluteURL('/s');
|
$url = OC::$server->getURLGenerator()->getAbsoluteURL('/s');
|
||||||
} else {
|
} else {
|
||||||
$url = OC::$server->getURLGenerator()->getAbsoluteURL(OC::$server->getURLGenerator()->linkTo('', 'public.php').'?service='.$service);
|
$url = OC::$server->getURLGenerator()->getAbsoluteURL(OC::$server->getURLGenerator()->linkTo('', 'public.php') . '?service=' . $service);
|
||||||
}
|
}
|
||||||
return $url . (($add_slash && $service[strlen($service) - 1] != '/') ? '/' : '');
|
return $url . (($add_slash && $service[strlen($service) - 1] != '/') ? '/' : '');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a human file size
|
* Make a human file size
|
||||||
|
*
|
||||||
* @param int $bytes file size in bytes
|
* @param int $bytes file size in bytes
|
||||||
* @return string a human readable file size
|
* @return string a human readable file size
|
||||||
*
|
*
|
||||||
|
@ -104,6 +106,7 @@ class OC_Helper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a php file size
|
* Make a php file size
|
||||||
|
*
|
||||||
* @param int $bytes file size in bytes
|
* @param int $bytes file size in bytes
|
||||||
* @return string a php parseable file size
|
* @return string a php parseable file size
|
||||||
*
|
*
|
||||||
|
@ -130,6 +133,7 @@ class OC_Helper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make a computer file size
|
* Make a computer file size
|
||||||
|
*
|
||||||
* @param string $str file size in human readable format
|
* @param string $str file size in human readable format
|
||||||
* @return float a file size in bytes
|
* @return float a file size in bytes
|
||||||
*
|
*
|
||||||
|
@ -172,6 +176,7 @@ class OC_Helper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recursive copying of folders
|
* Recursive copying of folders
|
||||||
|
*
|
||||||
* @param string $src source folder
|
* @param string $src source folder
|
||||||
* @param string $dest target folder
|
* @param string $dest target folder
|
||||||
*
|
*
|
||||||
|
@ -194,6 +199,7 @@ class OC_Helper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recursive deletion of folders
|
* Recursive deletion of folders
|
||||||
|
*
|
||||||
* @param string $dir path to the folder
|
* @param string $dir path to the folder
|
||||||
* @param bool $deleteSelf if set to false only the content of the folder will be deleted
|
* @param bool $deleteSelf if set to false only the content of the folder will be deleted
|
||||||
* @return bool
|
* @return bool
|
||||||
|
@ -393,6 +399,7 @@ class OC_Helper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* performs a search in a nested array
|
* performs a search in a nested array
|
||||||
|
*
|
||||||
* @param array $haystack the array to be searched
|
* @param array $haystack the array to be searched
|
||||||
* @param string $needle the search string
|
* @param string $needle the search string
|
||||||
* @param string $index optional, only search this key name
|
* @param string $index optional, only search this key name
|
||||||
|
@ -425,7 +432,7 @@ class OC_Helper {
|
||||||
* @return int number of bytes representing
|
* @return int number of bytes representing
|
||||||
*/
|
*/
|
||||||
public static function maxUploadFilesize($dir, $freeSpace = null) {
|
public static function maxUploadFilesize($dir, $freeSpace = null) {
|
||||||
if (is_null($freeSpace) || $freeSpace < 0){
|
if (is_null($freeSpace) || $freeSpace < 0) {
|
||||||
$freeSpace = self::freeSpace($dir);
|
$freeSpace = self::freeSpace($dir);
|
||||||
}
|
}
|
||||||
return min($freeSpace, self::uploadLimit());
|
return min($freeSpace, self::uploadLimit());
|
||||||
|
@ -443,7 +450,7 @@ class OC_Helper {
|
||||||
$freeSpace = max($freeSpace, 0);
|
$freeSpace = max($freeSpace, 0);
|
||||||
return $freeSpace;
|
return $freeSpace;
|
||||||
} else {
|
} else {
|
||||||
return (INF > 0)? INF: PHP_INT_MAX; // work around https://bugs.php.net/bug.php?id=69188
|
return (INF > 0) ? INF : PHP_INT_MAX; // work around https://bugs.php.net/bug.php?id=69188
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -510,7 +517,7 @@ class OC_Helper {
|
||||||
if (empty($paths)) {
|
if (empty($paths)) {
|
||||||
$paths = '/usr/local/bin /usr/bin /opt/bin /bin';
|
$paths = '/usr/local/bin /usr/bin /opt/bin /bin';
|
||||||
} else {
|
} else {
|
||||||
$paths = str_replace(':',' ',getenv('PATH'));
|
$paths = str_replace(':', ' ', getenv('PATH'));
|
||||||
}
|
}
|
||||||
$command = 'find ' . $paths . ' -name ' . escapeshellarg($program) . ' 2> /dev/null';
|
$command = 'find ' . $paths . ' -name ' . escapeshellarg($program) . ' 2> /dev/null';
|
||||||
exec($command, $output, $returnCode);
|
exec($command, $output, $returnCode);
|
||||||
|
@ -533,6 +540,11 @@ class OC_Helper {
|
||||||
* @throws \OCP\Files\NotFoundException
|
* @throws \OCP\Files\NotFoundException
|
||||||
*/
|
*/
|
||||||
public static function getStorageInfo($path, $rootInfo = null) {
|
public static function getStorageInfo($path, $rootInfo = null) {
|
||||||
|
$memcache = \OC::$server->getMemCacheFactory()->create('storageInfo');
|
||||||
|
$cached = $memcache->get($rootInfo ? '__root__' : $path);
|
||||||
|
if (is_array($cached)) {
|
||||||
|
return $cached;
|
||||||
|
}
|
||||||
// return storage info without adding mount points
|
// return storage info without adding mount points
|
||||||
$includeExtStorage = \OC::$server->getSystemConfig()->getValue('quota_include_external_storage', false);
|
$includeExtStorage = \OC::$server->getSystemConfig()->getValue('quota_include_external_storage', false);
|
||||||
|
|
||||||
|
@ -597,10 +609,20 @@ class OC_Helper {
|
||||||
$ownerId = $storage->getOwner($path);
|
$ownerId = $storage->getOwner($path);
|
||||||
$ownerDisplayName = '';
|
$ownerDisplayName = '';
|
||||||
$owner = \OC::$server->getUserManager()->get($ownerId);
|
$owner = \OC::$server->getUserManager()->get($ownerId);
|
||||||
if($owner) {
|
if ($owner) {
|
||||||
$ownerDisplayName = $owner->getDisplayName();
|
$ownerDisplayName = $owner->getDisplayName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$memcache->set($rootInfo ? '__root__' : $path, [
|
||||||
|
'free' => $free,
|
||||||
|
'used' => $used,
|
||||||
|
'quota' => $quota,
|
||||||
|
'total' => $total,
|
||||||
|
'relative' => $relative,
|
||||||
|
'owner' => $ownerId,
|
||||||
|
'ownerDisplayName' => $ownerDisplayName,
|
||||||
|
], 5 * 60);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'free' => $free,
|
'free' => $free,
|
||||||
'used' => $used,
|
'used' => $used,
|
||||||
|
@ -645,6 +667,7 @@ class OC_Helper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the config file is set manually to read-only
|
* Returns whether the config file is set manually to read-only
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function isReadOnlyConfigEnabled() {
|
public static function isReadOnlyConfigEnabled() {
|
||||||
|
|
Loading…
Reference in New Issue