Merge pull request #59477 from nextcloud/fix/noid/preview-scan-bulk-fetch-chunking

fix(previews): fix chunking for querybuilder
This commit is contained in:
Anna 2026-05-06 16:27:30 +02:00 committed by GitHub
commit 5d7cdb8fb5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 20 deletions

View file

@ -312,18 +312,17 @@ class LocalPreviewStorage implements IPreviewStorage {
$result = [];
$qb = $this->connection->getTypedQueryBuilder();
$qb->selectColumns('fileid', 'storage', 'etag', 'mimetype')
->from('filecache');
->from('filecache')
->where($qb->expr()->in('fileid', $qb->createParameter('fileIds')))
->runAcrossAllShards();
foreach (array_chunk($fileIds, 1000) as $chunk) {
$qb->andWhere(
$qb->expr()->in('fileid', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY))
);
$qb->setParameter('fileIds', $chunk, IQueryBuilder::PARAM_INT_ARRAY);
$rows = $qb->executeQuery();
while ($row = $rows->fetchAssociative()) {
$result[(int)$row['fileid']] = $row;
}
$rows->closeCursor();
}
$rows = $qb->runAcrossAllShards()
->executeQuery();
while ($row = $rows->fetchAssociative()) {
$result[(int)$row['fileid']] = $row;
}
$rows->closeCursor();
return $result;
}
@ -340,18 +339,17 @@ class LocalPreviewStorage implements IPreviewStorage {
$result = [];
$qb = $this->connection->getTypedQueryBuilder();
$qb->selectColumns('fileid', 'storage', 'etag', 'mimetype', 'parent', 'path_hash')
->from('filecache');
->from('filecache')
->where($qb->expr()->in('path_hash', $qb->createParameter('pathHashes')))
->runAcrossAllShards();
foreach (array_chunk($pathHashes, 1000) as $chunk) {
$qb->andWhere(
$qb->expr()->in('path_hash', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_STR_ARRAY))
);
$qb->setParameter('pathHashes', $chunk, IQueryBuilder::PARAM_STR_ARRAY);
$rows = $qb->executeQuery();
while ($row = $rows->fetchAssociative()) {
$result[$row['path_hash']] = $row;
}
$rows->closeCursor();
}
$rows = $qb->runAcrossAllShards()
->executeQuery();
while ($row = $rows->fetchAssociative()) {
$result[$row['path_hash']] = $row;
}
$rows->closeCursor();
return $result;
}

View file

@ -129,6 +129,7 @@ class LocalPreviewStorageTest extends TestCase {
$qbMock = $this->createMock(ITypedQueryBuilder::class);
$qbMock->method('selectColumns')->willReturnSelf();
$qbMock->method('from')->willReturnSelf();
$qbMock->method('where')->willReturnSelf();
$qbMock->method('andWhere')->willReturnSelf();
$qbMock->method('runAcrossAllShards')->willReturnSelf();
$qbMock->method('executeQuery')->willReturn($resultMock);