cach user folder for file search results

This commit is contained in:
Jörn Friedrich Dreyer 2015-04-13 11:29:10 +02:00
parent c3fbc2b6fd
commit b717681e3a
1 changed files with 11 additions and 2 deletions

View File

@ -25,6 +25,7 @@
namespace OC\Search\Result;
use OC\Files\Filesystem;
use OCP\Files\FileInfo;
use OCP\Files\Folder;
/**
* A found file
@ -91,6 +92,11 @@ class File extends \OCP\Search\Result {
$this->mime = $data->getMimetype();
}
/**
* @var Folder $userFolderCache
*/
static protected $userFolderCache = null;
/**
* converts a path relative to the users files folder
* eg /user/files/foo.txt -> /foo.txt
@ -98,8 +104,11 @@ class File extends \OCP\Search\Result {
* @return string relative path
*/
protected function getRelativePath ($path) {
$root = \OC::$server->getUserFolder();
return $root->getRelativePath($path);
if (!isset(self::$userFolderCache)) {
$user = \OC::$server->getUserSession()->getUser()->getUID();
self::$userFolderCache = \OC::$server->getUserFolder($user);
}
return self::$userFolderCache->getRelativePath($path);
}
}