summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@users.noreply.github.com>2024-03-06 18:57:54 +0100
committerGitHub <noreply@github.com>2024-03-06 18:57:54 +0100
commitdfae067bbc8f794299b0933785ea34b816c2311f (patch)
treee3d307340d43eddd5dae8b313f0776639dec6acb /lib
parentb3a2bb8ae8f8476925786c22e2f5960570bed1f2 (diff)
parent51019fda7a74816ca38962d899e7b641a4d5f88e (diff)
downloadnextcloud-server-dfae067bbc8f794299b0933785ea34b816c2311f.tar.gz
nextcloud-server-dfae067bbc8f794299b0933785ea34b816c2311f.zip
Merge pull request #43437 from nextcloud/cleanup-mount-by-id-duplication
use lazy user in UserMountCache for getting user for cached mount instead of duplicating logic
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Files/Config/UserMountCache.php41
1 files changed, 17 insertions, 24 deletions
diff --git a/lib/private/Files/Config/UserMountCache.php b/lib/private/Files/Config/UserMountCache.php
index 27d84e93838..8275eee7b9f 100644
--- a/lib/private/Files/Config/UserMountCache.php
+++ b/lib/private/Files/Config/UserMountCache.php
@@ -28,6 +28,7 @@
*/
namespace OC\Files\Config;
+use OC\User\LazyUser;
use OCP\Cache\CappedMemoryCache;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Diagnostics\IEventLogger;
@@ -213,13 +214,10 @@ class UserMountCache implements IUserMountCache {
/**
* @param array $row
* @param (callable(CachedMountInfo): string)|null $pathCallback
- * @return CachedMountInfo|null
+ * @return CachedMountInfo
*/
- private function dbRowToMountInfo(array $row, ?callable $pathCallback = null): ?ICachedMountInfo {
- $user = $this->userManager->get($row['user_id']);
- if (is_null($user)) {
- return null;
- }
+ private function dbRowToMountInfo(array $row, ?callable $pathCallback = null): ICachedMountInfo {
+ $user = new LazyUser($row['user_id'], $this->userManager);
$mount_id = $row['mount_id'];
if (!is_null($mount_id)) {
$mount_id = (int)$mount_id;
@@ -253,6 +251,9 @@ class UserMountCache implements IUserMountCache {
*/
public function getMountsForUser(IUser $user) {
$userUID = $user->getUID();
+ if (!$this->userManager->userExists($userUID)) {
+ return [];
+ }
if (!isset($this->mountsForUsers[$userUID])) {
$builder = $this->connection->getQueryBuilder();
$query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'mount_provider_class')
@@ -370,30 +371,22 @@ class UserMountCache implements IUserMountCache {
} catch (NotFoundException $e) {
return [];
}
- $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->createPositionalParameter($storageId, IQueryBuilder::PARAM_INT)));
-
- if ($user) {
- $query->andWhere($builder->expr()->eq('user_id', $builder->createPositionalParameter($user)));
- }
+ $mountsForStorage = $this->getMountsForStorageId($storageId, $user);
- $result = $query->execute();
- $rows = $result->fetchAll();
- $result->closeCursor();
- // filter mounts that are from the same storage but a different directory
- $filteredMounts = array_filter($rows, function (array $row) use ($internalPath, $fileId) {
- if ($fileId === (int)$row['root_id']) {
+ // 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 = $row['path'] ?? '';
+ $internalMountPath = $mount->getRootInternalPath();
+
+ return $internalMountPath === '' || str_starts_with($internalPath, $internalMountPath . '/');
+ });
- return $internalMountPath === '' || substr($internalPath, 0, strlen($internalMountPath) + 1) === $internalMountPath . '/';
+ $filteredMounts = array_filter($filteredMounts, function (ICachedMountInfo $mount) {
+ return $this->userManager->userExists($mount->getUser()->getUID());
});
- $filteredMounts = array_filter(array_map([$this, 'dbRowToMountInfo'], $filteredMounts));
return array_map(function (ICachedMountInfo $mount) use ($internalPath) {
return new CachedMountFileInfo(
$mount->getUser(),