]> source.dussan.org Git - nextcloud-server.git/commitdiff
optimize LazyUserFolder::getMountPoint 36609/head
authorRobin Appelman <robin@icewind.nl>
Wed, 8 Feb 2023 12:48:42 +0000 (13:48 +0100)
committerRobin Appelman <robin@icewind.nl>
Mon, 13 Feb 2023 14:13:50 +0000 (15:13 +0100)
no need to do a full setup

Signed-off-by: Robin Appelman <robin@icewind.nl>
lib/private/Files/Node/LazyUserFolder.php
lib/private/Files/Node/Root.php

index c85a356ddd324884eff1cef082ebb8e5d9a188f1..81009532dbfd3ae0ca74730ed7fec3f317a0dd09 100644 (file)
@@ -26,6 +26,7 @@ namespace OC\Files\Node;
 use OCP\Files\FileInfo;
 use OCP\Constants;
 use OCP\Files\IRootFolder;
+use OCP\Files\Mount\IMountManager;
 use OCP\Files\NotFoundException;
 use OCP\IUser;
 
@@ -33,10 +34,12 @@ class LazyUserFolder extends LazyFolder {
        private IRootFolder $root;
        private IUser $user;
        private string $path;
+       private IMountManager $mountManager;
 
-       public function __construct(IRootFolder $rootFolder, IUser $user) {
+       public function __construct(IRootFolder $rootFolder, IUser $user, IMountManager $mountManager) {
                $this->root = $rootFolder;
                $this->user = $user;
+               $this->mountManager = $mountManager;
                $this->path = '/' . $user->getUID() . '/files';
                parent::__construct(function () use ($user) {
                        try {
@@ -61,9 +64,20 @@ class LazyUserFolder extends LazyFolder {
 
        /**
         * @param int $id
-        * @return \OC\Files\Node\Node[]
+        * @return \OCP\Files\Node[]
         */
        public function getById($id) {
                return $this->root->getByIdInPath((int)$id, $this->getPath());
        }
+
+       public function getMountPoint() {
+               if ($this->folder !== null) {
+                       return $this->folder->getMountPoint();
+               }
+               $mountPoint = $this->mountManager->find('/' . $this->user->getUID());
+               if (is_null($mountPoint)) {
+                       throw new \Exception("No mountpoint for user folder");
+               }
+               return $mountPoint;
+       }
 }
index 29cdbb987c350810b738c48f3284f410474f1f63..e9fb14e5364b9199466d09ff77a54041288f38e2 100644 (file)
@@ -395,7 +395,7 @@ class Root extends Folder implements IRootFolder {
                                        $folder = $this->newFolder('/' . $userId . '/files');
                                }
                        } else {
-                               $folder = new LazyUserFolder($this, $userObject);
+                               $folder = new LazyUserFolder($this, $userObject, $this->mountManager);
                        }
 
                        $this->userFolderCache->set($userId, $folder);