Add pathcache

* If we find the mountpoint for a path cache it
* If we modify the mount points empty the pathCache

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2018-03-26 19:53:10 +02:00
parent 6868da9958
commit 37233471b6
No known key found for this signature in database
GPG Key ID: F941078878347C0C
1 changed files with 19 additions and 4 deletions

View File

@ -26,21 +26,28 @@ declare(strict_types=1);
namespace OC\Files\Mount; namespace OC\Files\Mount;
use \OC\Files\Filesystem; use OC\Cache\CappedMemoryCache;
use OC\Files\Filesystem;
use OCP\Files\Mount\IMountManager; use OCP\Files\Mount\IMountManager;
use OCP\Files\Mount\IMountPoint; use OCP\Files\Mount\IMountPoint;
class Manager implements IMountManager { class Manager implements IMountManager {
/** /** @var MountPoint[] */
* @var MountPoint[]
*/
private $mounts = []; private $mounts = [];
/** @var CappedMemoryCache */
private $pathCache;
public function __construct() {
$this->pathCache = new CappedMemoryCache();
}
/** /**
* @param IMountPoint $mount * @param IMountPoint $mount
*/ */
public function addMount(IMountPoint $mount) { public function addMount(IMountPoint $mount) {
$this->mounts[$mount->getMountPoint()] = $mount; $this->mounts[$mount->getMountPoint()] = $mount;
$this->pathCache->clear();
} }
/** /**
@ -52,6 +59,7 @@ class Manager implements IMountManager {
$mountPoint .= '/'; $mountPoint .= '/';
} }
unset($this->mounts[$mountPoint]); unset($this->mounts[$mountPoint]);
$this->pathCache->clear();
} }
/** /**
@ -61,6 +69,7 @@ class Manager implements IMountManager {
public function moveMount(string $mountPoint, string $target){ public function moveMount(string $mountPoint, string $target){
$this->mounts[$target] = $this->mounts[$mountPoint]; $this->mounts[$target] = $this->mounts[$mountPoint];
unset($this->mounts[$mountPoint]); unset($this->mounts[$mountPoint]);
$this->pathCache->clear();
} }
/** /**
@ -76,6 +85,10 @@ class Manager implements IMountManager {
return $this->mounts[$path]; return $this->mounts[$path];
} }
if (isset($this->pathCache[$path])) {
return $this->pathCache[$path];
}
\OC_Hook::emit('OC_Filesystem', 'get_mountpoint', ['path' => $path]); \OC_Hook::emit('OC_Filesystem', 'get_mountpoint', ['path' => $path]);
$foundMountPoint = ''; $foundMountPoint = '';
$mountPoints = array_keys($this->mounts); $mountPoints = array_keys($this->mounts);
@ -88,6 +101,7 @@ class Manager implements IMountManager {
} }
if (isset($this->mounts[$foundMountPoint])) { if (isset($this->mounts[$foundMountPoint])) {
$this->pathCache[$path] = $this->mounts[$foundMountPoint];
return $this->mounts[$foundMountPoint]; return $this->mounts[$foundMountPoint];
} }
@ -116,6 +130,7 @@ class Manager implements IMountManager {
public function clear() { public function clear() {
$this->mounts = []; $this->mounts = [];
$this->pathCache->clear();
} }
/** /**