mirror of
https://github.com/nextcloud/server.git
synced 2026-06-09 08:44:07 -04:00
Merge pull request #57525 from nextcloud/carl/usermountcache-loop-optimization
perf(UserMountCache): Optimize loop
This commit is contained in:
commit
3a9173015c
1 changed files with 12 additions and 9 deletions
|
|
@ -493,11 +493,10 @@ class UserMountCache implements IUserMountCache {
|
|||
}
|
||||
|
||||
public function getMountForPath(IUser $user, string $path): ICachedMountInfo {
|
||||
$mounts = $this->getMountsForUser($user);
|
||||
$mountPoints = array_map(function (ICachedMountInfo $mount) {
|
||||
return $mount->getMountPoint();
|
||||
}, $mounts);
|
||||
$mounts = array_combine($mountPoints, $mounts);
|
||||
$mounts = [];
|
||||
foreach ($this->getMountsForUser($user) as $mount) {
|
||||
$mounts[$mount->getMountPoint()] = $mount;
|
||||
}
|
||||
|
||||
$current = rtrim($path, '/');
|
||||
// walk up the directory tree until we find a path that has a mountpoint set
|
||||
|
|
@ -521,10 +520,14 @@ class UserMountCache implements IUserMountCache {
|
|||
|
||||
public function getMountsInPath(IUser $user, string $path): array {
|
||||
$path = rtrim($path, '/') . '/';
|
||||
$mounts = $this->getMountsForUser($user);
|
||||
return array_filter($mounts, function (ICachedMountInfo $mount) use ($path) {
|
||||
return $mount->getMountPoint() !== $path && str_starts_with($mount->getMountPoint(), $path);
|
||||
});
|
||||
$result = [];
|
||||
foreach ($this->getMountsForUser($user) as $key => $mount) {
|
||||
$mountPoint = $mount->getMountPoint();
|
||||
if ($mountPoint !== $path && str_starts_with($mountPoint, $path)) {
|
||||
$result[$key] = $mount;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function removeMount(string $mountPoint): void {
|
||||
|
|
|
|||
Loading…
Reference in a new issue