Skip to content
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 results of normalizePath #13235

Merged
merged 1 commit into from Jan 10, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/private/files/filesystem.php
Expand Up @@ -47,6 +47,8 @@ class Filesystem {

static private $usersSetup = array();

static private $normalizedPathCache = array();

/**
* classname which used for hooks handling
* used as signalclass in OC_Hooks::emit()
Expand Down Expand Up @@ -713,6 +715,12 @@ static public function hasUpdated($path, $time) {
* @return string
*/
public static function normalizePath($path, $stripTrailingSlash = true, $isAbsolutePath = false) {
$cacheKey = $path.'-'.-$stripTrailingSlash.'-'.$isAbsolutePath;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is -$stripTrailingSlash intentional? Looks wrong and might confuse in the future?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All hail to the typo. – Thanks for spotting. Shouldn't produce any bugs but was certainly not intended.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tada: #13305


if(isset(self::$normalizedPathCache[$cacheKey])) {
return self::$normalizedPathCache[$cacheKey];
}

if ($path == '') {
return '/';
}
Expand Down Expand Up @@ -756,7 +764,10 @@ public static function normalizePath($path, $stripTrailingSlash = true, $isAbsol
//normalize unicode if possible
$path = \OC_Util::normalizeUnicode($path);

return $windows_drive_letter . $path;
$normalizedPath = $windows_drive_letter . $path;
self::$normalizedPathCache[$cacheKey] = $normalizedPath;

return $normalizedPath;
}

/**
Expand Down