Skip to content

Commit c34dc32

Browse files
committed
fix: hint table for columns where needed for sharded queries
Signed-off-by: Robin Appelman <[email protected]>
1 parent 208c87c commit c34dc32

File tree

2 files changed

+51
-49
lines changed

2 files changed

+51
-49
lines changed

lib/ACL/RuleManager.php

+21-20
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ public function getRulesForFilesByPath(IUser $user, int $storageId, array $fileP
9191
$rows = [];
9292
foreach (array_chunk($hashes, 1000) as $chunk) {
9393
$query = $this->connection->getQueryBuilder();
94-
$query->select(['f.fileid', 'mapping_type', 'mapping_id', 'mask', 'a.permissions', 'path'])
94+
$query->select(['f.fileid', 'mapping_type', 'mapping_id', 'mask', 'a.permissions', 'f.path'])
9595
->from('group_folders_acl', 'a')
9696
->innerJoin('a', 'filecache', 'f', $query->expr()->eq('f.fileid', 'a.fileid'))
97-
->where($query->expr()->in('path_hash', $query->createNamedParameter($chunk, IQueryBuilder::PARAM_STR_ARRAY)))
98-
->andWhere($query->expr()->eq('storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
97+
->where($query->expr()->in('f.path_hash', $query->createNamedParameter($chunk, IQueryBuilder::PARAM_STR_ARRAY)))
98+
->andWhere($query->expr()->eq('f.storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
9999
->andWhere($query->expr()->orX(...array_map(function (IUserMapping $userMapping) use ($query) {
100100
return $query->expr()->andX(
101101
$query->expr()->eq('mapping_type', $query->createNamedParameter($userMapping->getType())),
@@ -129,20 +129,21 @@ public function getRulesForFilesByParent(IUser $user, int $storageId, string $pa
129129
}
130130

131131
$query = $this->connection->getQueryBuilder();
132-
$query->select(['f.fileid', 'mapping_type', 'mapping_id', 'mask', 'a.permissions', 'path'])
132+
$query->select(['f.fileid', 'a.mapping_type', 'a.mapping_id', 'a.mask', 'a.permissions', 'f.path'])
133133
->from('filecache', 'f')
134134
->leftJoin('f', 'group_folders_acl', 'a', $query->expr()->eq('f.fileid', 'a.fileid'))
135-
->andWhere($query->expr()->eq('parent', $query->createNamedParameter($parentId, IQueryBuilder::PARAM_INT)))
135+
->andWhere($query->expr()->eq('f.parent', $query->createNamedParameter($parentId, IQueryBuilder::PARAM_INT)))
136+
->andWhere($query->expr()->eq('f.storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
136137
->andWhere(
137138
$query->expr()->orX(
138139
$query->expr()->andX(
139-
$query->expr()->isNull('mapping_type'),
140-
$query->expr()->isNull('mapping_id')
140+
$query->expr()->isNull('a.mapping_type'),
141+
$query->expr()->isNull('a.mapping_id')
141142
),
142143
...array_map(function (IUserMapping $userMapping) use ($query) {
143144
return $query->expr()->andX(
144-
$query->expr()->eq('mapping_type', $query->createNamedParameter($userMapping->getType())),
145-
$query->expr()->eq('mapping_id', $query->createNamedParameter($userMapping->getId()))
145+
$query->expr()->eq('a.mapping_type', $query->createNamedParameter($userMapping->getType())),
146+
$query->expr()->eq('a.mapping_id', $query->createNamedParameter($userMapping->getId()))
146147
);
147148
}, $userMappings)
148149
)
@@ -185,11 +186,11 @@ public function getAllRulesForPaths(int $storageId, array $filePaths): array {
185186
return md5(trim($path, '/'));
186187
}, $filePaths);
187188
$query = $this->connection->getQueryBuilder();
188-
$query->select(['f.fileid', 'mapping_type', 'mapping_id', 'mask', 'a.permissions', 'path'])
189+
$query->select(['f.fileid', 'mapping_type', 'mapping_id', 'mask', 'a.permissions', 'f.path'])
189190
->from('group_folders_acl', 'a')
190191
->innerJoin('a', 'filecache', 'f', $query->expr()->eq('f.fileid', 'a.fileid'))
191-
->where($query->expr()->in('path_hash', $query->createNamedParameter($hashes, IQueryBuilder::PARAM_STR_ARRAY)))
192-
->andWhere($query->expr()->eq('storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)));
192+
->where($query->expr()->in('f.path_hash', $query->createNamedParameter($hashes, IQueryBuilder::PARAM_STR_ARRAY)))
193+
->andWhere($query->expr()->eq('f.storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)));
193194

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

@@ -219,14 +220,14 @@ private function rulesByPath(array $rows, array $result = []): array {
219220
*/
220221
public function getAllRulesForPrefix(int $storageId, string $prefix): array {
221222
$query = $this->connection->getQueryBuilder();
222-
$query->select(['f.fileid', 'mapping_type', 'mapping_id', 'mask', 'a.permissions', 'path'])
223+
$query->select(['f.fileid', 'mapping_type', 'mapping_id', 'mask', 'a.permissions', 'f.path'])
223224
->from('group_folders_acl', 'a')
224225
->innerJoin('a', 'filecache', 'f', $query->expr()->eq('f.fileid', 'a.fileid'))
225226
->where($query->expr()->orX(
226-
$query->expr()->like('path', $query->createNamedParameter($this->connection->escapeLikeParameter($prefix) . '/%')),
227-
$query->expr()->eq('path_hash', $query->createNamedParameter(md5($prefix)))
227+
$query->expr()->like('f.path', $query->createNamedParameter($this->connection->escapeLikeParameter($prefix) . '/%')),
228+
$query->expr()->eq('f.path_hash', $query->createNamedParameter(md5($prefix)))
228229
))
229-
->andWhere($query->expr()->eq('storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)));
230+
->andWhere($query->expr()->eq('f.storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)));
230231

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

@@ -243,14 +244,14 @@ public function getRulesForPrefix(IUser $user, int $storageId, string $prefix):
243244
$userMappings = $this->userMappingManager->getMappingsForUser($user);
244245

245246
$query = $this->connection->getQueryBuilder();
246-
$query->select(['f.fileid', 'mapping_type', 'mapping_id', 'mask', 'a.permissions', 'path'])
247+
$query->select(['f.fileid', 'mapping_type', 'mapping_id', 'mask', 'a.permissions', 'f.path'])
247248
->from('group_folders_acl', 'a')
248249
->innerJoin('a', 'filecache', 'f', $query->expr()->eq('f.fileid', 'a.fileid'))
249250
->where($query->expr()->orX(
250-
$query->expr()->like('path', $query->createNamedParameter($this->connection->escapeLikeParameter($prefix) . '/%')),
251-
$query->expr()->eq('path_hash', $query->createNamedParameter(md5($prefix)))
251+
$query->expr()->like('f.path', $query->createNamedParameter($this->connection->escapeLikeParameter($prefix) . '/%')),
252+
$query->expr()->eq('f.path_hash', $query->createNamedParameter(md5($prefix)))
252253
))
253-
->andWhere($query->expr()->eq('storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
254+
->andWhere($query->expr()->eq('f.storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
254255
->andWhere($query->expr()->orX(...array_map(function (IUserMapping $userMapping) use ($query) {
255256
return $query->expr()->andX(
256257
$query->expr()->eq('mapping_type', $query->createNamedParameter($userMapping->getType())),

lib/Folder/FolderManager.php

+30-29
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,9 @@ private function getGroupFolderRootId(int $rootStorageId): int {
123123
private function joinQueryWithFileCache(IQueryBuilder $query, int $rootStorageId): void {
124124
$query->leftJoin('f', 'filecache', 'c', $query->expr()->andX(
125125
// concat with empty string to work around missing cast to string
126-
$query->expr()->eq('c.name', $query->func()->concat('f.folder_id', $query->expr()->literal(""))),
127-
$query->expr()->eq('c.parent', $query->createNamedParameter($this->getGroupFolderRootId($rootStorageId)))
126+
$query->expr()->eq('c.name', $query->func()->concat('f.folder_id', $query->expr()->literal(''))),
127+
$query->expr()->eq('c.parent', $query->createNamedParameter($this->getGroupFolderRootId($rootStorageId))),
128+
$query->expr()->eq('c.storage', $query->createNamedParameter($rootStorageId)),
128129
));
129130
}
130131

@@ -137,7 +138,7 @@ public function getAllFoldersWithSize(int $rootStorageId): array {
137138

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

140-
$query->select('folder_id', 'mount_point', 'quota', 'size', 'acl')
141+
$query->select('folder_id', 'mount_point', 'quota', 'c.size', 'acl')
141142
->from('group_folders', 'f');
142143
$this->joinQueryWithFileCache($query, $rootStorageId);
143144

@@ -173,7 +174,7 @@ public function getAllFoldersForUserWithSize(int $rootStorageId, IUser $user): a
173174

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

176-
$query->select('f.folder_id', 'mount_point', 'quota', 'size', 'acl')
177+
$query->select('f.folder_id', 'mount_point', 'quota', 'c.size', 'acl')
177178
->from('group_folders', 'f')
178179
->innerJoin(
179180
'f',
@@ -283,7 +284,7 @@ public function getFolder(int $id, int $rootStorageId = 0) {
283284

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

286-
$query->select('folder_id', 'mount_point', 'quota', 'size', 'acl')
287+
$query->select('folder_id', 'mount_point', 'quota', 'c.size', 'acl')
287288
->from('group_folders', 'f')
288289
->where($query->expr()->eq('folder_id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
289290
$this->joinQueryWithFileCache($query, $rootStorageId);
@@ -496,18 +497,18 @@ public function getFoldersForGroup(string $groupId, int $rootStorageId = 0): arr
496497
'mount_point',
497498
'quota',
498499
'acl',
499-
'fileid',
500-
'storage',
501-
'path',
502-
'name',
503-
'mimetype',
504-
'mimepart',
505-
'size',
506-
'mtime',
507-
'storage_mtime',
508-
'etag',
509-
'encrypted',
510-
'parent'
500+
'c.fileid',
501+
'c.storage',
502+
'c.path',
503+
'c.name',
504+
'c.mimetype',
505+
'c.mimepart',
506+
'c.size',
507+
'c.mtime',
508+
'c.storage_mtime',
509+
'c.etag',
510+
'c.encrypted',
511+
'c.parent'
511512
)
512513
->selectAlias('a.permissions', 'group_permissions')
513514
->selectAlias('c.permissions', 'permissions')
@@ -547,18 +548,18 @@ public function getFoldersForGroups(array $groupIds, int $rootStorageId = 0): ar
547548
'mount_point',
548549
'quota',
549550
'acl',
550-
'fileid',
551-
'storage',
552-
'path',
553-
'name',
554-
'mimetype',
555-
'mimepart',
556-
'size',
557-
'mtime',
558-
'storage_mtime',
559-
'etag',
560-
'encrypted',
561-
'parent'
551+
'c.fileid',
552+
'c.storage',
553+
'c.path',
554+
'c.name',
555+
'c.mimetype',
556+
'c.mimepart',
557+
'c.size',
558+
'c.mtime',
559+
'c.storage_mtime',
560+
'c.etag',
561+
'c.encrypted',
562+
'c.parent'
562563
)
563564
->selectAlias('a.permissions', 'group_permissions')
564565
->selectAlias('c.permissions', 'permissions')

0 commit comments

Comments
 (0)