cache OC\Files\Mount\Manager::findIn results

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2018-08-16 19:02:00 +02:00
parent 2aad504e93
commit 969176b116
No known key found for this signature in database
GPG Key ID: 42B69D8A64526EFB
2 changed files with 28 additions and 8 deletions

View File

@ -25,21 +25,28 @@
namespace OC\Files\Mount;
use OC\Cache\CappedMemoryCache;
use \OC\Files\Filesystem;
use OCP\Files\Mount\IMountManager;
use OCP\Files\Mount\IMountPoint;
class Manager implements IMountManager {
/**
* @var MountPoint[]
*/
private $mounts = array();
/** @var MountPoint[] */
private $mounts = [];
/** @var CappedMemoryCache */
private $inPathCache;
public function __construct() {
$this->inPathCache = new CappedMemoryCache();
}
/**
* @param IMountPoint $mount
*/
public function addMount(IMountPoint $mount) {
$this->mounts[$mount->getMountPoint()] = $mount;
$this->inPathCache->clear();
}
/**
@ -51,15 +58,17 @@ class Manager implements IMountManager {
$mountPoint .= '/';
}
unset($this->mounts[$mountPoint]);
$this->inPathCache->clear();
}
/**
* @param string $mountPoint
* @param string $target
*/
public function moveMount($mountPoint, $target){
public function moveMount($mountPoint, $target) {
$this->mounts[$target] = $this->mounts[$mountPoint];
unset($this->mounts[$mountPoint]);
$this->inPathCache->clear();
}
/**
@ -73,7 +82,7 @@ class Manager implements IMountManager {
$path = Filesystem::normalizePath($path);
$current = $path;
while(true) {
while (true) {
$mountPoint = $current . '/';
if (isset($this->mounts[$mountPoint])) {
return $this->mounts[$mountPoint];
@ -99,7 +108,12 @@ class Manager implements IMountManager {
public function findIn($path) {
\OC_Util::setupFS();
$path = $this->formatPath($path);
$result = array();
if (isset($this->inPathCache[$path])) {
return $this->inPathCache[$path];
}
$result = [];
$pathLength = strlen($path);
$mountPoints = array_keys($this->mounts);
foreach ($mountPoints as $mountPoint) {
@ -107,11 +121,14 @@ class Manager implements IMountManager {
$result[] = $this->mounts[$mountPoint];
}
}
$this->inPathCache[$path] = $result;
return $result;
}
public function clear() {
$this->mounts = array();
$this->mounts = [];
$this->inPathCache->clear();
}
/**

View File

@ -1721,6 +1721,9 @@ class View {
*/
if ($mount->getStorage()) {
$cache = $mount->getStorage()->getCache();
if (!$cache) {
throw new NotFoundException(sprintf('File with id "%s" has not been found.', $id));
}
$internalPath = $cache->getPathById($id);
if (is_string($internalPath)) {
$fullPath = $mount->getMountPoint() . $internalPath;