Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
more efficient way to detect added and removed mounts
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Aug 16, 2018
commit c300516e518fff07276a2e6e221ae903c7fe8b26
32 changes: 23 additions & 9 deletions lib/private/Files/Config/UserMountCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,31 @@ public function registerMounts(IUser $user, array $mounts) {
}
}, $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);

Expand Down