Skip to content

Commit

Permalink
don't trigger fs setup in groupfolder setup
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Jun 29, 2018
1 parent 4e9287b commit e06ecaf
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 20 deletions.
3 changes: 1 addition & 2 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public function __construct(array $urlParams = []) {

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

$container->registerService(MountProvider::class, function (IAppContainer $c) {
Expand Down
20 changes: 11 additions & 9 deletions lib/Controller/FolderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,43 +27,45 @@
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\OCSController;
use OCP\Files\IRootFolder;
use OCP\IRequest;

class FolderController extends OCSController {
/** @var FolderManager */
private $manager;
/** @var MountProvider */
private $mountProvider;
/** @var IRootFolder */
private $rootFolder;

/**
* @param string $AppName
* @param IRequest $request
* @param FolderManager $manager
* @param MountProvider $mountProvider
*/
public function __construct(
$AppName,
IRequest $request,
FolderManager $manager,
MountProvider $mountProvider
MountProvider $mountProvider,
IRootFolder $rootFolder
) {
parent::__construct($AppName, $request);
$this->manager = $manager;
$this->mountProvider = $mountProvider;
$this->rootFolder = $rootFolder;
}

public function getFolders() {
return new DataResponse($this->manager->getAllFolders());
return new DataResponse($this->manager->getAllFoldersWithSize($this->getRootFolderStorageId()));
}

/**
* @param int $id
* @return DataResponse
*/
public function getFolder($id) {
return new DataResponse($this->manager->getFolder((int)$id));
return new DataResponse($this->manager->getFolder((int)$id, $this->getRootFolderStorageId()));
}

private function getRootFolderStorageId() {
return $this->rootFolder->getMountPoint()->getNumericStorageId();
}

/**
* @param string $mountpoint
Expand Down
37 changes: 29 additions & 8 deletions lib/Folder/FolderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,51 @@
class FolderManager {
/** @var IDBConnection */
private $connection;
/** @var int */
private $rootStorageId;

/**
* @param IDBConnection $connection
* @param int $rootStorageId
*/
public function __construct(IDBConnection $connection, $rootStorageId) {
public function __construct(IDBConnection $connection) {
$this->connection = $connection;
$this->rootStorageId = $rootStorageId;
}

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

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

$query->select('folder_id', 'mount_point', 'quota', 'size')
->from('group_folders', 'f');

$rows = $query->execute()->fetchAll();

$folderMap = [];
foreach ($rows as $row) {
$id = $row['folder_id'];
$folderMap[$id] = [
'id' => $id,
'mount_point' => $row['mount_point'],
'groups' => isset($applicableMap[$id]) ? $applicableMap[$id] : [],
'quota' => $row['quota'],
'size' => 0
];
}

return $folderMap;
}

public function getAllFoldersWithSize($rootStorageId) {
$applicableMap = $this->getAllApplicable();

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

$folderPath = $query->func()->concat($query->createNamedParameter('__groupfolders/'), 'folder_id');

$query->select('folder_id', 'mount_point', 'quota', 'size')
->from('group_folders', 'f')
->leftJoin('f', 'filecache', 'c', $query->expr()->andX(
$query->expr()->eq('path_hash', $query->func()->md5($folderPath)),
$query->expr()->eq('storage', $query->createNamedParameter($this->rootStorageId, IQueryBuilder::PARAM_INT))
$query->expr()->eq('storage', $query->createNamedParameter($rootStorageId, IQueryBuilder::PARAM_INT))
));

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

public function getFolder($id) {
public function getFolder($id, $rootStorageId) {
$applicableMap = $this->getAllApplicable();

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

Expand Down
2 changes: 1 addition & 1 deletion tests/Folder/FolderManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class FolderManagerTest extends TestCase {
protected function setUp() {
parent::setUp();

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

Expand Down

0 comments on commit e06ecaf

Please sign in to comment.