From 37233471b6698f798c9f0b9bf0286c4d9c342204 Mon Sep 17 00:00:00 2001
From: Roeland Jago Douma <roeland@famdouma.nl>
Date: Mon, 26 Mar 2018 19:53:10 +0200
Subject: 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>
---
 lib/private/Files/Mount/Manager.php | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

(limited to 'lib')

diff --git a/lib/private/Files/Mount/Manager.php b/lib/private/Files/Mount/Manager.php
index d98d45ae0b7..f27dfaacc8b 100644
--- a/lib/private/Files/Mount/Manager.php
+++ b/lib/private/Files/Mount/Manager.php
@@ -26,21 +26,28 @@ declare(strict_types=1);
 
 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\IMountPoint;
 
 class Manager implements IMountManager {
-	/**
-	 * @var MountPoint[]
-	 */
+	/** @var MountPoint[] */
 	private $mounts = [];
 
+	/** @var CappedMemoryCache */
+	private $pathCache;
+
+	public function __construct() {
+		$this->pathCache = new CappedMemoryCache();
+	}
+
 	/**
 	 * @param IMountPoint $mount
 	 */
 	public function addMount(IMountPoint $mount) {
 		$this->mounts[$mount->getMountPoint()] = $mount;
+		$this->pathCache->clear();
 	}
 
 	/**
@@ -52,6 +59,7 @@ class Manager implements IMountManager {
 			$mountPoint .= '/';
 		}
 		unset($this->mounts[$mountPoint]);
+		$this->pathCache->clear();
 	}
 
 	/**
@@ -61,6 +69,7 @@ class Manager implements IMountManager {
 	public function moveMount(string $mountPoint, string $target){
 		$this->mounts[$target] = $this->mounts[$mountPoint];
 		unset($this->mounts[$mountPoint]);
+		$this->pathCache->clear();
 	}
 
 	/**
@@ -76,6 +85,10 @@ class Manager implements IMountManager {
 			return $this->mounts[$path];
 		}
 
+		if (isset($this->pathCache[$path])) {
+			return $this->pathCache[$path];
+		}
+
 		\OC_Hook::emit('OC_Filesystem', 'get_mountpoint', ['path' => $path]);
 		$foundMountPoint = '';
 		$mountPoints = array_keys($this->mounts);
@@ -88,6 +101,7 @@ class Manager implements IMountManager {
 		}
 
 		if (isset($this->mounts[$foundMountPoint])) {
+			$this->pathCache[$path] = $this->mounts[$foundMountPoint];
 			return $this->mounts[$foundMountPoint];
 		}
 
@@ -116,6 +130,7 @@ class Manager implements IMountManager {
 
 	public function clear() {
 		$this->mounts = [];
+		$this->pathCache->clear();
 	}
 
 	/**
-- 
cgit v1.2.3