diff options
-rw-r--r-- | lib/private/Files/Config/UserMountCache.php | 69 |
1 files changed, 45 insertions, 24 deletions
diff --git a/lib/private/Files/Config/UserMountCache.php b/lib/private/Files/Config/UserMountCache.php index 3e53a67a044..9761f26972f 100644 --- a/lib/private/Files/Config/UserMountCache.php +++ b/lib/private/Files/Config/UserMountCache.php @@ -362,34 +362,55 @@ class UserMountCache implements IUserMountCache { } catch (NotFoundException $e) { return []; } - $mountsForStorage = $this->getMountsForStorageId($storageId, $user); - // filter mounts that are from the same storage but not a parent of the file we care about - $filteredMounts = array_filter($mountsForStorage, function (ICachedMountInfo $mount) use ($internalPath, $fileId) { - if ($fileId === $mount->getRootId()) { - return true; - } - $internalMountPath = $mount->getRootInternalPath(); + $builder = $this->connection->getQueryBuilder(); + $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class') + ->from('mounts', 'm') + ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid')) + ->where($builder->expr()->eq('storage_id', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))) + ->andWhere( + $builder->expr()->orX( + $builder->expr()->eq('f.fileid', $builder->createNamedParameter($fileId)), + $builder->expr()->eq('f.path', $builder->createNamedParameter('')), + $builder->expr()->isNull('f.path'), + $builder->expr()->eq( + $builder->func()->concat('f.path', $builder->createNamedParameter('/')), + $builder->func()->substring( + $builder->createNamedParameter($internalPath), + $builder->createNamedParameter(1, IQueryBuilder::PARAM_INT), + $builder->func()->add( + $builder->func()->charLength('f.path'), + $builder->createNamedParameter(1, IQueryBuilder::PARAM_INT), + ), + ), + ), + ) + ); - return $internalMountPath === '' || str_starts_with($internalPath, $internalMountPath . '/'); - }); + if ($user !== null) { + $query->andWhere($builder->expr()->eq('user_id', $builder->createNamedParameter($user))); + } + $result = $query->executeQuery(); - $filteredMounts = array_values(array_filter($filteredMounts, function (ICachedMountInfo $mount) { - return $this->userManager->userExists($mount->getUser()->getUID()); - })); - - return array_map(function (ICachedMountInfo $mount) use ($internalPath) { - return new CachedMountFileInfo( - $mount->getUser(), - $mount->getStorageId(), - $mount->getRootId(), - $mount->getMountPoint(), - $mount->getMountId(), - $mount->getMountProvider(), - $mount->getRootInternalPath(), - $internalPath + $mounts = []; + while ($row = $result->fetch()) { + if (!$this->userManager->userExists($row['user_id'])) { + continue; + } + + $mounts[] = new CachedMountFileInfo( + new LazyUser($row['user_id'], $this->userManager), + (int)$row['storage_id'], + (int)$row['root_id'], + $row['mount_point'], + $row['mount_id'] === null ? null : (int)$row['mount_id'], + $row['mount_provider_class'] ?? '', + $row['path'] ?? '', + $internalPath, ); - }, $filteredMounts); + } + + return $mounts; } /** |