Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
optimize LazyUserFolder::getMountPoint
no need to do a full setup

Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Feb 13, 2023
commit d6818ba894bc12f7c5fcca746e8b7be3e7ab18df
18 changes: 16 additions & 2 deletions lib/private/Files/Node/LazyUserFolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,20 @@
use OCP\Files\FileInfo;
use OCP\Constants;
use OCP\Files\IRootFolder;
use OCP\Files\Mount\IMountManager;
use OCP\Files\NotFoundException;
use OCP\IUser;

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 {
Expand All @@ -61,9 +64,20 @@ public function get($path) {

/**
* @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;
}
}
2 changes: 1 addition & 1 deletion lib/private/Files/Node/Root.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ public function getUserFolder($userId) {
$folder = $this->newFolder('/' . $userId . '/files');
}
} else {
$folder = new LazyUserFolder($this, $userObject);
$folder = new LazyUserFolder($this, $userObject, $this->mountManager);
}

$this->userFolderCache->set($userId, $folder);
Expand Down