Fix Dropbox metadata cache with trimmed paths

Makes sure that the paths are trimmed to avoid duplicate entries like
"/test" and "test". This should make this storage slightly faster by
reducing the cache misses.
remotes/origin/dav-zip-folder
Vincent Petry 2015-10-19 20:49:54 +07:00
parent 90e34e26bd
commit d795643ef9
1 changed files with 9 additions and 5 deletions

@ -64,7 +64,7 @@ class Dropbox extends \OC\Files\Storage\Common {
* @param string $path * @param string $path
*/ */
private function deleteMetaData($path) { private function deleteMetaData($path) {
$path = $this->root.$path; $path = ltrim($this->root.$path, '/');
if (isset($this->metaData[$path])) { if (isset($this->metaData[$path])) {
unset($this->metaData[$path]); unset($this->metaData[$path]);
return true; return true;
@ -72,6 +72,10 @@ class Dropbox extends \OC\Files\Storage\Common {
return false; return false;
} }
private function setMetaData($path, $metaData) {
$this->metaData[ltrim($path, '/')] = $metaData;
}
/** /**
* Returns the path's metadata * Returns the path's metadata
* @param string $path path for which to return the metadata * @param string $path path for which to return the metadata
@ -80,7 +84,7 @@ class Dropbox extends \OC\Files\Storage\Common {
* false, null if the file doesn't exist or "false" if the operation failed * false, null if the file doesn't exist or "false" if the operation failed
*/ */
private function getDropBoxMetaData($path, $list = false) { private function getDropBoxMetaData($path, $list = false) {
$path = $this->root.$path; $path = ltrim($this->root.$path, '/');
if ( ! $list && isset($this->metaData[$path])) { if ( ! $list && isset($this->metaData[$path])) {
return $this->metaData[$path]; return $this->metaData[$path];
} else { } else {
@ -96,14 +100,14 @@ class Dropbox extends \OC\Files\Storage\Common {
// Cache folder's contents // Cache folder's contents
foreach ($response['contents'] as $file) { foreach ($response['contents'] as $file) {
if (!isset($file['is_deleted']) || !$file['is_deleted']) { if (!isset($file['is_deleted']) || !$file['is_deleted']) {
$this->metaData[$path.'/'.basename($file['path'])] = $file; $this->setMetaData($path.'/'.basename($file['path']), $file);
$contents[] = $file; $contents[] = $file;
} }
} }
unset($response['contents']); unset($response['contents']);
} }
if (!isset($response['is_deleted']) || !$response['is_deleted']) { if (!isset($response['is_deleted']) || !$response['is_deleted']) {
$this->metaData[$path] = $response; $this->setMetaData($path, $response);
} }
// Return contents of folder only // Return contents of folder only
return $contents; return $contents;
@ -116,7 +120,7 @@ class Dropbox extends \OC\Files\Storage\Common {
$response = $this->dropbox->getMetaData($requestPath, 'false'); $response = $this->dropbox->getMetaData($requestPath, 'false');
if (!isset($response['is_deleted']) || !$response['is_deleted']) { if (!isset($response['is_deleted']) || !$response['is_deleted']) {
$this->metaData[$path] = $response; $this->setMetaData($path, $response);
return $response; return $response;
} }
return null; return null;