From c897e2af8e43f37dda08d99a1a3460b6aa90da67 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 16 Aug 2018 19:56:49 +0200 Subject: [PATCH] more efficient way to detect added and removed mounts Signed-off-by: Robin Appelman --- apps/files_sharing/lib/SharedMount.php | 4 --- lib/private/Files/Config/UserMountCache.php | 30 +++++++++++++++------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/apps/files_sharing/lib/SharedMount.php b/apps/files_sharing/lib/SharedMount.php index ba3efaf3f8..bf274f2c2f 100644 --- a/apps/files_sharing/lib/SharedMount.php +++ b/apps/files_sharing/lib/SharedMount.php @@ -140,11 +140,7 @@ class SharedMount extends MountPoint implements MoveableMount { while ($view->file_exists($path) || isset($mountpoints[$absolutePath])) { $path = Filesystem::normalizePath($dir . '/' . $name . ' (' . $i . ')' . $ext); $absolutePath = $this->recipientView->getAbsolutePath($path) . '/'; - var_dump($absolutePath); $i++; - if ($i > 10) { - return $path; - } } return $path; diff --git a/lib/private/Files/Config/UserMountCache.php b/lib/private/Files/Config/UserMountCache.php index 095a0df7e0..07c6e1f2d6 100644 --- a/lib/private/Files/Config/UserMountCache.php +++ b/lib/private/Files/Config/UserMountCache.php @@ -102,17 +102,31 @@ class UserMountCache implements IUserMountCache { } }, $mounts); $newMounts = array_values(array_filter($newMounts)); + $newMountRootIds = array_map(function (ICachedMountInfo $mount) { + return $mount->getRootId(); + }, $newMounts); + $newMounts = array_combine($newMountRootIds, $newMounts); $cachedMounts = $this->getMountsForUser($user); - $mountDiff = function (ICachedMountInfo $mount1, ICachedMountInfo $mount2) { - // since we are only looking for mounts for a specific user comparing on root id is enough - return $mount1->getRootId() - $mount2->getRootId(); - }; + $cachedMountRootIds = array_map(function (ICachedMountInfo $mount) { + return $mount->getRootId(); + }, $cachedMounts); + $cachedMounts = array_combine($cachedMountRootIds, $cachedMounts); - /** @var ICachedMountInfo[] $addedMounts */ - $addedMounts = array_udiff($newMounts, $cachedMounts, $mountDiff); - /** @var ICachedMountInfo[] $removedMounts */ - $removedMounts = array_udiff($cachedMounts, $newMounts, $mountDiff); + $addedMounts = []; + $removedMounts = []; + + foreach ($newMounts as $rootId => $newMount) { + if (!isset($cachedMounts[$rootId])) { + $addedMounts[] = $newMount; + } + } + + foreach ($cachedMounts as $rootId => $cachedMount) { + if (!isset($newMounts[$rootId])) { + $removedMounts[] = $cachedMount; + } + } $changedMounts = $this->findChangedMounts($newMounts, $cachedMounts);