get files_external mounts more efficiently
This commit is contained in:
parent
8741acf8a6
commit
b573c5b8f8
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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']);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue