diff options
author | blizzz <blizzz@arthur-schiwon.de> | 2021-04-30 10:52:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-30 10:52:44 +0200 |
commit | 36c9441c37368ad2cd0e044dc5f2adcf036e92d8 (patch) | |
tree | 5ac12ac2b07f4e9efa3af17534c59d00f7f083b0 | |
parent | f3baab3159be20a7f643e1370016bbba756b8d9a (diff) | |
parent | 1e2cf820c89b774d0a8d6f85bfd8d2fd1b4ab2d6 (diff) | |
download | nextcloud-server-36c9441c37368ad2cd0e044dc5f2adcf036e92d8.tar.gz nextcloud-server-36c9441c37368ad2cd0e044dc5f2adcf036e92d8.zip |
Merge pull request #26593 from nextcloud/bugfix/noid/getMountsForFileId-performance
Filter mounts for file id before trying to get user information
-rw-r--r-- | lib/private/Files/Config/UserMountCache.php | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/private/Files/Config/UserMountCache.php b/lib/private/Files/Config/UserMountCache.php index fddd2d956a1..29d3256d61b 100644 --- a/lib/private/Files/Config/UserMountCache.php +++ b/lib/private/Files/Config/UserMountCache.php @@ -326,18 +326,30 @@ class UserMountCache implements IUserMountCache { } catch (NotFoundException $e) { return []; } - $mountsForStorage = $this->getMountsForStorageId($storageId, $user); + $builder = $this->connection->getQueryBuilder(); + $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path') + ->from('mounts', 'm') + ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid')) + ->where($builder->expr()->eq('storage_id', $builder->createPositionalParameter($storageId, IQueryBuilder::PARAM_INT))); + if ($user) { + $query->andWhere($builder->expr()->eq('user_id', $builder->createPositionalParameter($user))); + } + + $result = $query->execute(); + $rows = $result->fetchAll(); + $result->closeCursor(); // filter mounts that are from the same storage but a different directory - $filteredMounts = array_filter($mountsForStorage, function (ICachedMountInfo $mount) use ($internalPath, $fileId) { - if ($fileId === $mount->getRootId()) { + $filteredMounts = array_filter($rows, function (array $row) use ($internalPath, $fileId) { + if ($fileId === (int)$row['root_id']) { return true; } - $internalMountPath = $mount->getRootInternalPath(); + $internalMountPath = isset($row['path']) ? $row['path'] : ''; return $internalMountPath === '' || substr($internalPath, 0, strlen($internalMountPath) + 1) === $internalMountPath . '/'; }); + $filteredMounts = array_filter(array_map([$this, 'dbRowToMountInfo'], $filteredMounts)); return array_map(function (ICachedMountInfo $mount) use ($internalPath) { return new CachedMountFileInfo( $mount->getUser(), |