summaryrefslogtreecommitdiffstats
path: root/apps/files_external
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2016-09-02 14:55:45 +0200
committerRobin Appelman <robin@icewind.nl>2016-09-05 14:34:20 +0200
commitb573c5b8f807eec913c494b0ec4a54f91ff143e6 (patch)
tree752a12323cd77859138cb9e8ba46e4b1acc2b919 /apps/files_external
parent8741acf8a6dfb3919c43d3cee5a9c13f6c1e4b9f (diff)
downloadnextcloud-server-b573c5b8f807eec913c494b0ec4a54f91ff143e6.tar.gz
nextcloud-server-b573c5b8f807eec913c494b0ec4a54f91ff143e6.zip
get files_external mounts more efficiently
Diffstat (limited to 'apps/files_external')
-rw-r--r--apps/files_external/lib/Config/ConfigAdapter.php49
-rw-r--r--apps/files_external/lib/Service/DBConfigService.php23
-rw-r--r--apps/files_external/lib/Service/UserGlobalStoragesService.php25
3 files changed, 68 insertions, 29 deletions
diff --git a/apps/files_external/lib/Config/ConfigAdapter.php b/apps/files_external/lib/Config/ConfigAdapter.php
index 00366135ea4..5d8e30b6da6 100644
--- a/apps/files_external/lib/Config/ConfigAdapter.php
+++ b/apps/files_external/lib/Config/ConfigAdapter.php
@@ -126,7 +126,7 @@ class ConfigAdapter implements IMountProvider {
$this->userStoragesService->setUser($user);
$this->userGlobalStoragesService->setUser($user);
- foreach ($this->userGlobalStoragesService->getUniqueStorages() as $storage) {
+ foreach ($this->userGlobalStoragesService->getAllStoragesForUser() as $storage) {
try {
$this->prepareStorageConfig($storage, $user);
$impl = $this->constructStorage($storage);
@@ -147,35 +147,26 @@ class ConfigAdapter implements IMountProvider {
$impl = new FailedStorage(['exception' => $e]);
}
- $mount = new MountPoint(
- $impl,
- '/' . $user->getUID() . '/files' . $storage->getMountPoint(),
- null,
- $loader,
- $storage->getMountOptions(),
- $storage->getId()
- );
- $mounts[$storage->getMountPoint()] = $mount;
- }
-
- foreach ($this->userStoragesService->getStorages() as $storage) {
- try {
- $this->prepareStorageConfig($storage, $user);
- $impl = $this->constructStorage($storage);
- } catch (\Exception $e) {
- // propagate exception into filesystem
- $impl = new FailedStorage(['exception' => $e]);
+ if ($storage->getType() === StorageConfig::MOUNT_TYPE_PERSONAl) {
+ $mount = new PersonalMount(
+ $this->userStoragesService,
+ $storage->getId(),
+ $impl,
+ '/' . $user->getUID() . '/files' . $storage->getMountPoint(),
+ null,
+ $loader,
+ $storage->getMountOptions()
+ );
+ } else {
+ $mount = new MountPoint(
+ $impl,
+ '/' . $user->getUID() . '/files' . $storage->getMountPoint(),
+ null,
+ $loader,
+ $storage->getMountOptions(),
+ $storage->getId()
+ );
}
-
- $mount = new PersonalMount(
- $this->userStoragesService,
- $storage->getId(),
- $impl,
- '/' . $user->getUID() . '/files' . $storage->getMountPoint(),
- null,
- $loader,
- $storage->getMountOptions()
- );
$mounts[$storage->getMountPoint()] = $mount;
}
diff --git a/apps/files_external/lib/Service/DBConfigService.php b/apps/files_external/lib/Service/DBConfigService.php
index 61cca9a0224..00612d17643 100644
--- a/apps/files_external/lib/Service/DBConfigService.php
+++ b/apps/files_external/lib/Service/DBConfigService.php
@@ -89,6 +89,29 @@ class DBConfigService {
return $this->getMountsFromQuery($query);
}
+ public function getMountsForUser($userId, $groupIds) {
+ $builder = $this->connection->getQueryBuilder();
+ $query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type'])
+ ->from('external_mounts', 'm')
+ ->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id'))
+ ->where($builder->expr()->orX(
+ $builder->expr()->andX( // global mounts
+ $builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_GLOBAL, IQueryBuilder::PARAM_INT)),
+ $builder->expr()->isNull('a.value')
+ ),
+ $builder->expr()->andX( // mounts for user
+ $builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_USER, IQueryBuilder::PARAM_INT)),
+ $builder->expr()->eq('a.value', $builder->createNamedParameter($userId))
+ ),
+ $builder->expr()->andX( // mounts for group
+ $builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_GROUP, IQueryBuilder::PARAM_INT)),
+ $builder->expr()->in('a.value', $builder->createNamedParameter($groupIds, IQueryBuilder::PARAM_INT_ARRAY))
+ )
+ ));
+
+ return $this->getMountsFromQuery($query);
+ }
+
/**
* Get admin defined mounts
*
diff --git a/apps/files_external/lib/Service/UserGlobalStoragesService.php b/apps/files_external/lib/Service/UserGlobalStoragesService.php
index c22508e57c4..355401bb84f 100644
--- a/apps/files_external/lib/Service/UserGlobalStoragesService.php
+++ b/apps/files_external/lib/Service/UserGlobalStoragesService.php
@@ -172,4 +172,29 @@ class UserGlobalStoragesService extends GlobalStoragesService {
}
return false;
}
+
+
+ /**
+ * Gets all storages for the user, admin, personal, global, etc
+ *
+ * @return StorageConfig[] array of storage configs
+ */
+ public function getAllStoragesForUser() {
+ if (is_null($this->getUser())) {
+ return [];
+ }
+ $groupIds = $this->groupManager->getUserGroupIds($this->getUser());
+ $mounts = $this->dbConfig->getMountsForUser($this->getUser()->getUID(), $groupIds);
+ $configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts);
+ $configs = array_filter($configs, function ($config) {
+ return $config instanceof StorageConfig;
+ });
+
+ $keys = array_map(function (StorageConfig $config) {
+ return $config->getId();
+ }, $configs);
+
+ $storages = array_combine($keys, $configs);
+ return array_filter($storages, [$this, 'validateStorage']);
+ }
}