Merge pull request #57525 from nextcloud/carl/usermountcache-loop-optimization

perf(UserMountCache): Optimize loop
This commit is contained in:
Stephan Orbaugh 2026-01-16 10:50:27 +01:00 committed by GitHub
commit 3a9173015c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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 {