Skip to content

Commit

Permalink
Revert "fix: hint table for columns where needed for sharded queries"
Browse files Browse the repository at this point in the history
This reverts commit c897828.
  • Loading branch information
icewind1991 committed Dec 19, 2024
1 parent 53b9338 commit 0e7b7b0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 50 deletions.
41 changes: 20 additions & 21 deletions lib/ACL/RuleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ public function getRulesForFilesByPath(IUser $user, int $storageId, array $fileP
$rows = [];
foreach (array_chunk($hashes, 1000) as $chunk) {
$query = $this->connection->getQueryBuilder();
$query->select(['f.fileid', 'mapping_type', 'mapping_id', 'mask', 'a.permissions', 'f.path'])
$query->select(['f.fileid', 'mapping_type', 'mapping_id', 'mask', 'a.permissions', 'path'])
->from('group_folders_acl', 'a')
->innerJoin('a', 'filecache', 'f', $query->expr()->eq('f.fileid', 'a.fileid'))
->where($query->expr()->in('f.path_hash', $query->createNamedParameter($chunk, IQueryBuilder::PARAM_STR_ARRAY)))
->andWhere($query->expr()->eq('f.storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
->where($query->expr()->in('path_hash', $query->createNamedParameter($chunk, IQueryBuilder::PARAM_STR_ARRAY)))
->andWhere($query->expr()->eq('storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->orX(...array_map(fn (IUserMapping $userMapping): ICompositeExpression => $query->expr()->andX(
$query->expr()->eq('mapping_type', $query->createNamedParameter($userMapping->getType())),
$query->expr()->eq('mapping_id', $query->createNamedParameter($userMapping->getId()))
Expand Down Expand Up @@ -117,20 +117,19 @@ public function getRulesForFilesByParent(IUser $user, int $storageId, string $pa
}

$query = $this->connection->getQueryBuilder();
$query->select(['f.fileid', 'a.mapping_type', 'a.mapping_id', 'a.mask', 'a.permissions', 'f.path'])
$query->select(['f.fileid', 'mapping_type', 'mapping_id', 'mask', 'a.permissions', 'path'])
->from('filecache', 'f')
->leftJoin('f', 'group_folders_acl', 'a', $query->expr()->eq('f.fileid', 'a.fileid'))
->andWhere($query->expr()->eq('f.parent', $query->createNamedParameter($parentId, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->eq('f.storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->eq('parent', $query->createNamedParameter($parentId, IQueryBuilder::PARAM_INT)))
->andWhere(
$query->expr()->orX(
$query->expr()->andX(
$query->expr()->isNull('a.mapping_type'),
$query->expr()->isNull('a.mapping_id')
$query->expr()->isNull('mapping_type'),
$query->expr()->isNull('mapping_id')
),
...array_map(fn (IUserMapping $userMapping): ICompositeExpression => $query->expr()->andX(
$query->expr()->eq('a.mapping_type', $query->createNamedParameter($userMapping->getType())),
$query->expr()->eq('a.mapping_id', $query->createNamedParameter($userMapping->getId()))
$query->expr()->eq('mapping_type', $query->createNamedParameter($userMapping->getType())),
$query->expr()->eq('mapping_id', $query->createNamedParameter($userMapping->getId()))
), $userMappings)
)
);
Expand Down Expand Up @@ -171,11 +170,11 @@ private function getId(int $storageId, string $path): int {
public function getAllRulesForPaths(int $storageId, array $filePaths): array {
$hashes = array_map(fn (string $path): string => md5(trim($path, '/')), $filePaths);
$query = $this->connection->getQueryBuilder();
$query->select(['f.fileid', 'mapping_type', 'mapping_id', 'mask', 'a.permissions', 'f.path'])
$query->select(['f.fileid', 'mapping_type', 'mapping_id', 'mask', 'a.permissions', 'path'])
->from('group_folders_acl', 'a')
->innerJoin('a', 'filecache', 'f', $query->expr()->eq('f.fileid', 'a.fileid'))
->where($query->expr()->in('f.path_hash', $query->createNamedParameter($hashes, IQueryBuilder::PARAM_STR_ARRAY)))
->andWhere($query->expr()->eq('f.storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)));
->where($query->expr()->in('path_hash', $query->createNamedParameter($hashes, IQueryBuilder::PARAM_STR_ARRAY)))
->andWhere($query->expr()->eq('storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)));

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

Expand Down Expand Up @@ -204,14 +203,14 @@ private function rulesByPath(array $rows, array $result = []): array {
*/
public function getAllRulesForPrefix(int $storageId, string $prefix): array {
$query = $this->connection->getQueryBuilder();
$query->select(['f.fileid', 'mapping_type', 'mapping_id', 'mask', 'a.permissions', 'f.path'])
$query->select(['f.fileid', 'mapping_type', 'mapping_id', 'mask', 'a.permissions', 'path'])
->from('group_folders_acl', 'a')
->innerJoin('a', 'filecache', 'f', $query->expr()->eq('f.fileid', 'a.fileid'))
->where($query->expr()->orX(
$query->expr()->like('f.path', $query->createNamedParameter($this->connection->escapeLikeParameter($prefix) . '/%')),
$query->expr()->eq('f.path_hash', $query->createNamedParameter(md5($prefix)))
$query->expr()->like('path', $query->createNamedParameter($this->connection->escapeLikeParameter($prefix) . '/%')),
$query->expr()->eq('path_hash', $query->createNamedParameter(md5($prefix)))
))
->andWhere($query->expr()->eq('f.storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)));
->andWhere($query->expr()->eq('storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)));

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

Expand All @@ -225,14 +224,14 @@ public function getRulesForPrefix(IUser $user, int $storageId, string $prefix):
$userMappings = $this->userMappingManager->getMappingsForUser($user);

$query = $this->connection->getQueryBuilder();
$query->select(['f.fileid', 'mapping_type', 'mapping_id', 'mask', 'a.permissions', 'f.path'])
$query->select(['f.fileid', 'mapping_type', 'mapping_id', 'mask', 'a.permissions', 'path'])
->from('group_folders_acl', 'a')
->innerJoin('a', 'filecache', 'f', $query->expr()->eq('f.fileid', 'a.fileid'))
->where($query->expr()->orX(
$query->expr()->like('f.path', $query->createNamedParameter($this->connection->escapeLikeParameter($prefix) . '/%')),
$query->expr()->eq('f.path_hash', $query->createNamedParameter(md5($prefix)))
$query->expr()->like('path', $query->createNamedParameter($this->connection->escapeLikeParameter($prefix) . '/%')),
$query->expr()->eq('path_hash', $query->createNamedParameter(md5($prefix)))
))
->andWhere($query->expr()->eq('f.storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->eq('storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
->andWhere($query->expr()->orX(...array_map(fn (IUserMapping $userMapping): ICompositeExpression => $query->expr()->andX(
$query->expr()->eq('mapping_type', $query->createNamedParameter($userMapping->getType())),
$query->expr()->eq('mapping_id', $query->createNamedParameter($userMapping->getId()))
Expand Down
57 changes: 28 additions & 29 deletions lib/Folder/FolderManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ private function joinQueryWithFileCache(IQueryBuilder $query, int $rootStorageId
$query->leftJoin('f', 'filecache', 'c', $query->expr()->andX(
// concat with empty string to work around missing cast to string
$query->expr()->eq('c.name', $query->func()->concat('f.folder_id', $query->expr()->literal(''))),
$query->expr()->eq('c.parent', $query->createNamedParameter($this->getGroupFolderRootId($rootStorageId))),
$query->expr()->eq('c.storage', $query->createNamedParameter($rootStorageId)),
$query->expr()->eq('c.parent', $query->createNamedParameter($this->getGroupFolderRootId($rootStorageId)))
));
}

Expand All @@ -137,7 +136,7 @@ public function getAllFoldersWithSize(int $rootStorageId): array {

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

$query->select('folder_id', 'mount_point', 'quota', 'c.size', 'acl')
$query->select('folder_id', 'mount_point', 'quota', 'size', 'acl')
->from('group_folders', 'f');
$this->joinQueryWithFileCache($query, $rootStorageId);

Expand Down Expand Up @@ -173,7 +172,7 @@ public function getAllFoldersForUserWithSize(int $rootStorageId, IUser $user): a

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

$query->select('f.folder_id', 'mount_point', 'quota', 'c.size', 'acl')
$query->select('f.folder_id', 'mount_point', 'quota', 'size', 'acl')
->from('group_folders', 'f')
->innerJoin(
'f',
Expand Down Expand Up @@ -286,7 +285,7 @@ public function getFolder(int $id, int $rootStorageId = 0): ?array {

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

$query->select('folder_id', 'mount_point', 'quota', 'c.size', 'acl')
$query->select('folder_id', 'mount_point', 'quota', 'size', 'acl')
->from('group_folders', 'f')
->where($query->expr()->eq('folder_id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
$this->joinQueryWithFileCache($query, $rootStorageId);
Expand Down Expand Up @@ -497,18 +496,18 @@ public function getFoldersForGroup(string $groupId, int $rootStorageId = 0): arr
'mount_point',
'quota',
'acl',
'c.fileid',
'c.storage',
'c.path',
'c.name',
'c.mimetype',
'c.mimepart',
'c.size',
'c.mtime',
'c.storage_mtime',
'c.etag',
'c.encrypted',
'c.parent'
'fileid',
'storage',
'path',
'name',
'mimetype',
'mimepart',
'size',
'mtime',
'storage_mtime',
'etag',
'encrypted',
'parent'
)
->selectAlias('a.permissions', 'group_permissions')
->selectAlias('c.permissions', 'permissions')
Expand Down Expand Up @@ -547,18 +546,18 @@ public function getFoldersForGroups(array $groupIds, int $rootStorageId = 0): ar
'mount_point',
'quota',
'acl',
'c.fileid',
'c.storage',
'c.path',
'c.name',
'c.mimetype',
'c.mimepart',
'c.size',
'c.mtime',
'c.storage_mtime',
'c.etag',
'c.encrypted',
'c.parent'
'fileid',
'storage',
'path',
'name',
'mimetype',
'mimepart',
'size',
'mtime',
'storage_mtime',
'etag',
'encrypted',
'parent'
)
->selectAlias('a.permissions', 'group_permissions')
->selectAlias('c.permissions', 'permissions')
Expand Down

0 comments on commit 0e7b7b0

Please sign in to comment.