more efficient way to detect added and removed mounts

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2018-08-16 19:56:49 +02:00
parent f2152ecda9
commit c897e2af8e
No known key found for this signature in database
GPG Key ID: 42B69D8A64526EFB
2 changed files with 22 additions and 12 deletions

View File

@ -140,11 +140,7 @@ class SharedMount extends MountPoint implements MoveableMount {
while ($view->file_exists($path) || isset($mountpoints[$absolutePath])) { while ($view->file_exists($path) || isset($mountpoints[$absolutePath])) {
$path = Filesystem::normalizePath($dir . '/' . $name . ' (' . $i . ')' . $ext); $path = Filesystem::normalizePath($dir . '/' . $name . ' (' . $i . ')' . $ext);
$absolutePath = $this->recipientView->getAbsolutePath($path) . '/'; $absolutePath = $this->recipientView->getAbsolutePath($path) . '/';
var_dump($absolutePath);
$i++; $i++;
if ($i > 10) {
return $path;
}
} }
return $path; return $path;

View File

@ -102,17 +102,31 @@ class UserMountCache implements IUserMountCache {
} }
}, $mounts); }, $mounts);
$newMounts = array_values(array_filter($newMounts)); $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); $cachedMounts = $this->getMountsForUser($user);
$mountDiff = function (ICachedMountInfo $mount1, ICachedMountInfo $mount2) { $cachedMountRootIds = array_map(function (ICachedMountInfo $mount) {
// since we are only looking for mounts for a specific user comparing on root id is enough return $mount->getRootId();
return $mount1->getRootId() - $mount2->getRootId(); }, $cachedMounts);
}; $cachedMounts = array_combine($cachedMountRootIds, $cachedMounts);
/** @var ICachedMountInfo[] $addedMounts */ $addedMounts = [];
$addedMounts = array_udiff($newMounts, $cachedMounts, $mountDiff); $removedMounts = [];
/** @var ICachedMountInfo[] $removedMounts */
$removedMounts = array_udiff($cachedMounts, $newMounts, $mountDiff); 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); $changedMounts = $this->findChangedMounts($newMounts, $cachedMounts);