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 f8116ad4cf
commit f7ae235372
No known key found for this signature in database
GPG Key ID: 42B69D8A64526EFB
1 changed files with 17 additions and 2 deletions

View File

@ -38,8 +38,12 @@ class Manager implements IMountManager {
/** @var CappedMemoryCache */
private $pathCache;
/** @var CappedMemoryCache */
private $inPathCache;
public function __construct() {
$this->pathCache = new CappedMemoryCache();
$this->inPathCache = new CappedMemoryCache();
}
/**
@ -48,6 +52,7 @@ class Manager implements IMountManager {
public function addMount(IMountPoint $mount) {
$this->mounts[$mount->getMountPoint()] = $mount;
$this->pathCache->clear();
$this->inPathCache->clear();
}
/**
@ -60,16 +65,18 @@ class Manager implements IMountManager {
}
unset($this->mounts[$mountPoint]);
$this->pathCache->clear();
$this->inPathCache->clear();
}
/**
* @param string $mountPoint
* @param string $target
*/
public function moveMount(string $mountPoint, string $target){
public function moveMount(string $mountPoint, string $target) {
$this->mounts[$target] = $this->mounts[$mountPoint];
unset($this->mounts[$mountPoint]);
$this->pathCache->clear();
$this->inPathCache->clear();
}
/**
@ -87,7 +94,7 @@ class Manager implements IMountManager {
}
$current = $path;
while(true) {
while (true) {
$mountPoint = $current . '/';
if (isset($this->mounts[$mountPoint])) {
$this->pathCache[$path] = $this->mounts[$mountPoint];
@ -114,6 +121,11 @@ class Manager implements IMountManager {
public function findIn(string $path): array {
\OC_Util::setupFS();
$path = $this->formatPath($path);
if (isset($this->inPathCache[$path])) {
return $this->inPathCache[$path];
}
$result = [];
$pathLength = \strlen($path);
$mountPoints = array_keys($this->mounts);
@ -122,12 +134,15 @@ class Manager implements IMountManager {
$result[] = $this->mounts[$mountPoint];
}
}
$this->inPathCache[$path] = $result;
return $result;
}
public function clear() {
$this->mounts = [];
$this->pathCache->clear();
$this->inPathCache->clear();
}
/**