Skip to content

Commit e06ecaf

Browse files
committed
don't trigger fs setup in groupfolder setup
Signed-off-by: Robin Appelman <[email protected]>
1 parent 4e9287b commit e06ecaf

File tree

4 files changed

+42
-20
lines changed

4 files changed

+42
-20
lines changed

β€Žlib/AppInfo/Application.phpβ€Ž

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ public function __construct(array $urlParams = []) {
3636

3737
$container = $this->getContainer();
3838
$container->registerService(FolderManager::class, function (IAppContainer $c) {
39-
$rootStorageId = $c->getServer()->getRootFolder()->getMountPoint()->getNumericStorageId();
40-
return new FolderManager($c->getServer()->getDatabaseConnection(), $rootStorageId);
39+
return new FolderManager($c->getServer()->getDatabaseConnection());
4140
});
4241

4342
$container->registerService(MountProvider::class, function (IAppContainer $c) {

β€Žlib/Controller/FolderController.phpβ€Ž

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,43 +27,45 @@
2727
use OCP\AppFramework\Http\DataResponse;
2828
use OCP\AppFramework\Http\JSONResponse;
2929
use OCP\AppFramework\OCSController;
30+
use OCP\Files\IRootFolder;
3031
use OCP\IRequest;
3132

3233
class FolderController extends OCSController {
3334
/** @var FolderManager */
3435
private $manager;
3536
/** @var MountProvider */
3637
private $mountProvider;
38+
/** @var IRootFolder */
39+
private $rootFolder;
3740

38-
/**
39-
* @param string $AppName
40-
* @param IRequest $request
41-
* @param FolderManager $manager
42-
* @param MountProvider $mountProvider
43-
*/
4441
public function __construct(
4542
$AppName,
4643
IRequest $request,
4744
FolderManager $manager,
48-
MountProvider $mountProvider
45+
MountProvider $mountProvider,
46+
IRootFolder $rootFolder
4947
) {
5048
parent::__construct($AppName, $request);
5149
$this->manager = $manager;
5250
$this->mountProvider = $mountProvider;
51+
$this->rootFolder = $rootFolder;
5352
}
5453

5554
public function getFolders() {
56-
return new DataResponse($this->manager->getAllFolders());
55+
return new DataResponse($this->manager->getAllFoldersWithSize($this->getRootFolderStorageId()));
5756
}
5857

5958
/**
6059
* @param int $id
6160
* @return DataResponse
6261
*/
6362
public function getFolder($id) {
64-
return new DataResponse($this->manager->getFolder((int)$id));
63+
return new DataResponse($this->manager->getFolder((int)$id, $this->getRootFolderStorageId()));
6564
}
6665

66+
private function getRootFolderStorageId() {
67+
return $this->rootFolder->getMountPoint()->getNumericStorageId();
68+
}
6769

6870
/**
6971
* @param string $mountpoint

β€Žlib/Folder/FolderManager.phpβ€Ž

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,51 @@
2828
class FolderManager {
2929
/** @var IDBConnection */
3030
private $connection;
31-
/** @var int */
32-
private $rootStorageId;
3331

3432
/**
3533
* @param IDBConnection $connection
36-
* @param int $rootStorageId
3734
*/
38-
public function __construct(IDBConnection $connection, $rootStorageId) {
35+
public function __construct(IDBConnection $connection) {
3936
$this->connection = $connection;
40-
$this->rootStorageId = $rootStorageId;
4137
}
4238

4339
public function getAllFolders() {
4440
$applicableMap = $this->getAllApplicable();
4541

4642
$query = $this->connection->getQueryBuilder();
4743

44+
$query->select('folder_id', 'mount_point', 'quota', 'size')
45+
->from('group_folders', 'f');
46+
47+
$rows = $query->execute()->fetchAll();
48+
49+
$folderMap = [];
50+
foreach ($rows as $row) {
51+
$id = $row['folder_id'];
52+
$folderMap[$id] = [
53+
'id' => $id,
54+
'mount_point' => $row['mount_point'],
55+
'groups' => isset($applicableMap[$id]) ? $applicableMap[$id] : [],
56+
'quota' => $row['quota'],
57+
'size' => 0
58+
];
59+
}
60+
61+
return $folderMap;
62+
}
63+
64+
public function getAllFoldersWithSize($rootStorageId) {
65+
$applicableMap = $this->getAllApplicable();
66+
67+
$query = $this->connection->getQueryBuilder();
68+
4869
$folderPath = $query->func()->concat($query->createNamedParameter('__groupfolders/'), 'folder_id');
4970

5071
$query->select('folder_id', 'mount_point', 'quota', 'size')
5172
->from('group_folders', 'f')
5273
->leftJoin('f', 'filecache', 'c', $query->expr()->andX(
5374
$query->expr()->eq('path_hash', $query->func()->md5($folderPath)),
54-
$query->expr()->eq('storage', $query->createNamedParameter($this->rootStorageId, IQueryBuilder::PARAM_INT))
75+
$query->expr()->eq('storage', $query->createNamedParameter($rootStorageId, IQueryBuilder::PARAM_INT))
5576
));
5677

5778
$rows = $query->execute()->fetchAll();
@@ -71,7 +92,7 @@ public function getAllFolders() {
7192
return $folderMap;
7293
}
7394

74-
public function getFolder($id) {
95+
public function getFolder($id, $rootStorageId) {
7596
$applicableMap = $this->getAllApplicable();
7697

7798
$query = $this->connection->getQueryBuilder();
@@ -82,7 +103,7 @@ public function getFolder($id) {
82103
->from('group_folders', 'f')
83104
->leftJoin('f', 'filecache', 'c', $query->expr()->andX(
84105
$query->expr()->eq('path_hash', $query->func()->md5($folderPath)),
85-
$query->expr()->eq('storage', $query->createNamedParameter($this->rootStorageId, IQueryBuilder::PARAM_INT))
106+
$query->expr()->eq('storage', $query->createNamedParameter($rootStorageId, IQueryBuilder::PARAM_INT))
86107
))
87108
->where($query->expr()->eq('folder_id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
88109

β€Žtests/Folder/FolderManagerTest.phpβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class FolderManagerTest extends TestCase {
3535
protected function setUp() {
3636
parent::setUp();
3737

38-
$this->manager = new FolderManager(\OC::$server->getDatabaseConnection(), -1);
38+
$this->manager = new FolderManager(\OC::$server->getDatabaseConnection());
3939
$this->clean();
4040
}
4141

0 commit comments

Comments
Β (0)