From f7ae235372ee5647003c407dff7eca83cb7a1322 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 16 Aug 2018 19:02:00 +0200 Subject: [PATCH] cache OC\Files\Mount\Manager::findIn results Signed-off-by: Robin Appelman --- lib/private/Files/Mount/Manager.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/private/Files/Mount/Manager.php b/lib/private/Files/Mount/Manager.php index b86142b4d5..1293b8549a 100644 --- a/lib/private/Files/Mount/Manager.php +++ b/lib/private/Files/Mount/Manager.php @@ -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(); } /**