Skip to content

Commit 5d7cdb8

Browse files
authored
Merge pull request #59477 from nextcloud/fix/noid/preview-scan-bulk-fetch-chunking
fix(previews): fix chunking for querybuilder
2 parents 2fcc7b1 + 0681ced commit 5d7cdb8

2 files changed

Lines changed: 19 additions & 20 deletions

File tree

lib/private/Preview/Storage/LocalPreviewStorage.php

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -312,18 +312,17 @@ private function fetchFilecacheByFileIds(array $fileIds): array {
312312
$result = [];
313313
$qb = $this->connection->getTypedQueryBuilder();
314314
$qb->selectColumns('fileid', 'storage', 'etag', 'mimetype')
315-
->from('filecache');
315+
->from('filecache')
316+
->where($qb->expr()->in('fileid', $qb->createParameter('fileIds')))
317+
->runAcrossAllShards();
316318
foreach (array_chunk($fileIds, 1000) as $chunk) {
317-
$qb->andWhere(
318-
$qb->expr()->in('fileid', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY))
319-
);
320-
}
321-
$rows = $qb->runAcrossAllShards()
322-
->executeQuery();
323-
while ($row = $rows->fetchAssociative()) {
324-
$result[(int)$row['fileid']] = $row;
319+
$qb->setParameter('fileIds', $chunk, IQueryBuilder::PARAM_INT_ARRAY);
320+
$rows = $qb->executeQuery();
321+
while ($row = $rows->fetchAssociative()) {
322+
$result[(int)$row['fileid']] = $row;
323+
}
324+
$rows->closeCursor();
325325
}
326-
$rows->closeCursor();
327326
return $result;
328327
}
329328

@@ -340,18 +339,17 @@ private function fetchFilecacheByPathHashes(array $pathHashes): array {
340339
$result = [];
341340
$qb = $this->connection->getTypedQueryBuilder();
342341
$qb->selectColumns('fileid', 'storage', 'etag', 'mimetype', 'parent', 'path_hash')
343-
->from('filecache');
342+
->from('filecache')
343+
->where($qb->expr()->in('path_hash', $qb->createParameter('pathHashes')))
344+
->runAcrossAllShards();
344345
foreach (array_chunk($pathHashes, 1000) as $chunk) {
345-
$qb->andWhere(
346-
$qb->expr()->in('path_hash', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_STR_ARRAY))
347-
);
348-
}
349-
$rows = $qb->runAcrossAllShards()
350-
->executeQuery();
351-
while ($row = $rows->fetchAssociative()) {
352-
$result[$row['path_hash']] = $row;
346+
$qb->setParameter('pathHashes', $chunk, IQueryBuilder::PARAM_STR_ARRAY);
347+
$rows = $qb->executeQuery();
348+
while ($row = $rows->fetchAssociative()) {
349+
$result[$row['path_hash']] = $row;
350+
}
351+
$rows->closeCursor();
353352
}
354-
$rows->closeCursor();
355353
return $result;
356354
}
357355

tests/lib/Preview/Storage/LocalPreviewStorageTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ private function buildQueryBuilderMock(array $rows): IQueryBuilder&MockObject {
129129
$qbMock = $this->createMock(ITypedQueryBuilder::class);
130130
$qbMock->method('selectColumns')->willReturnSelf();
131131
$qbMock->method('from')->willReturnSelf();
132+
$qbMock->method('where')->willReturnSelf();
132133
$qbMock->method('andWhere')->willReturnSelf();
133134
$qbMock->method('runAcrossAllShards')->willReturnSelf();
134135
$qbMock->method('executeQuery')->willReturn($resultMock);

0 commit comments

Comments
 (0)