-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cache the storage info for 5 min #3214
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ class OC_Helper { | |
|
||
/** | ||
* Creates an absolute url for public use | ||
* | ||
* @param string $service id | ||
* @param bool $add_slash | ||
* @return string the url | ||
|
@@ -62,13 +63,14 @@ public static function linkToPublic($service, $add_slash = false) { | |
if ($service === 'files') { | ||
$url = OC::$server->getURLGenerator()->getAbsoluteURL('/s'); | ||
} 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] != '/') ? '/' : ''); | ||
} | ||
|
||
/** | ||
* Make a human file size | ||
* | ||
* @param int $bytes file size in bytes | ||
* @return string a human readable file size | ||
* | ||
|
@@ -104,6 +106,7 @@ public static function humanFileSize($bytes) { | |
|
||
/** | ||
* Make a php file size | ||
* | ||
* @param int $bytes file size in bytes | ||
* @return string a php parseable file size | ||
* | ||
|
@@ -130,6 +133,7 @@ public static function phpFileSize($bytes) { | |
|
||
/** | ||
* Make a computer file size | ||
* | ||
* @param string $str file size in human readable format | ||
* @return float a file size in bytes | ||
* | ||
|
@@ -172,6 +176,7 @@ public static function computerFileSize($str) { | |
|
||
/** | ||
* Recursive copying of folders | ||
* | ||
* @param string $src source folder | ||
* @param string $dest target folder | ||
* | ||
|
@@ -194,6 +199,7 @@ static function copyr($src, $dest) { | |
|
||
/** | ||
* Recursive deletion of folders | ||
* | ||
* @param string $dir path to the folder | ||
* @param bool $deleteSelf if set to false only the content of the folder will be deleted | ||
* @return bool | ||
|
@@ -393,6 +399,7 @@ public static function mb_array_change_key_case($input, $case = MB_CASE_LOWER, $ | |
|
||
/** | ||
* performs a search in a nested array | ||
* | ||
* @param array $haystack the array to be searched | ||
* @param string $needle the search string | ||
* @param string $index optional, only search this key name | ||
|
@@ -425,7 +432,7 @@ public static function recursiveArraySearch($haystack, $needle, $index = null) { | |
* @return int number of bytes representing | ||
*/ | ||
public static function maxUploadFilesize($dir, $freeSpace = null) { | ||
if (is_null($freeSpace) || $freeSpace < 0){ | ||
if (is_null($freeSpace) || $freeSpace < 0) { | ||
$freeSpace = self::freeSpace($dir); | ||
} | ||
return min($freeSpace, self::uploadLimit()); | ||
|
@@ -443,7 +450,7 @@ public static function freeSpace($dir) { | |
$freeSpace = max($freeSpace, 0); | ||
return $freeSpace; | ||
} 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 @@ public static function findBinaryPath($program) { | |
if (empty($paths)) { | ||
$paths = '/usr/local/bin /usr/bin /opt/bin /bin'; | ||
} else { | ||
$paths = str_replace(':',' ',getenv('PATH')); | ||
$paths = str_replace(':', ' ', getenv('PATH')); | ||
} | ||
$command = 'find ' . $paths . ' -name ' . escapeshellarg($program) . ' 2> /dev/null'; | ||
exec($command, $output, $returnCode); | ||
|
@@ -533,6 +540,11 @@ public static function findBinaryPath($program) { | |
* @throws \OCP\Files\NotFoundException | ||
*/ | ||
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; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not unique across users. So this exposed the storage info of the user in the cache to all other users. Therefore I reverted this. #3515 Please come up with a proper implementation. And also take care of invalidate the cache when setting the quota. |
||
// return storage info without adding mount points | ||
$includeExtStorage = \OC::$server->getSystemConfig()->getValue('quota_include_external_storage', false); | ||
|
||
|
@@ -597,10 +609,20 @@ public static function getStorageInfo($path, $rootInfo = null) { | |
$ownerId = $storage->getOwner($path); | ||
$ownerDisplayName = ''; | ||
$owner = \OC::$server->getUserManager()->get($ownerId); | ||
if($owner) { | ||
if ($owner) { | ||
$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 [ | ||
'free' => $free, | ||
'used' => $used, | ||
|
@@ -645,6 +667,7 @@ private static function getGlobalStorageInfo() { | |
|
||
/** | ||
* Returns whether the config file is set manually to read-only | ||
* | ||
* @return bool | ||
*/ | ||
public static function isReadOnlyConfigEnabled() { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
memcached has a limit of 250 chars. So you need to sha1 or something the path here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done