fix(previews): use createParameter/setParameter to reuse query in chunk loop

AI-Assisted-By: claude-sonnet-4-6 <noreply@anthropic.com>
Signed-off-by: Anna Larch <anna@nextcloud.com>
AI-Assisted-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Anna Larch 2026-05-04 18:59:09 +02:00
parent 59144ace90
commit 0681ced203
2 changed files with 15 additions and 12 deletions

View file

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

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);