summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2018-08-16 19:56:49 +0200
committerRobin Appelman <robin@icewind.nl>2018-08-16 19:56:49 +0200
commitc300516e518fff07276a2e6e221ae903c7fe8b26 (patch)
tree5cae125297e72d9c00b14b6a50579c5f00869380 /lib/private
parent3155c1bd9a40cf0b77e392cf7bc9fad353c820ce (diff)
downloadnextcloud-server-c300516e518fff07276a2e6e221ae903c7fe8b26.tar.gz
nextcloud-server-c300516e518fff07276a2e6e221ae903c7fe8b26.zip
more efficient way to detect added and removed mounts
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Files/Config/UserMountCache.php32
1 files changed, 23 insertions, 9 deletions
diff --git a/lib/private/Files/Config/UserMountCache.php b/lib/private/Files/Config/UserMountCache.php
index 0b9501b4442..63abdf5fdeb 100644
--- a/lib/private/Files/Config/UserMountCache.php
+++ b/lib/private/Files/Config/UserMountCache.php
@@ -101,17 +101,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();
- };
-
- /** @var ICachedMountInfo[] $addedMounts */
- $addedMounts = array_udiff($newMounts, $cachedMounts, $mountDiff);
- /** @var ICachedMountInfo[] $removedMounts */
- $removedMounts = array_udiff($cachedMounts, $newMounts, $mountDiff);
+ $cachedMountRootIds = array_map(function (ICachedMountInfo $mount) {
+ return $mount->getRootId();
+ }, $cachedMounts);
+ $cachedMounts = array_combine($cachedMountRootIds, $cachedMounts);
+
+ $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);