diff --git a/lib/private/Preview/Storage/LocalPreviewStorage.php b/lib/private/Preview/Storage/LocalPreviewStorage.php index c5221a2b93d4a..13e6a7145167b 100644 --- a/lib/private/Preview/Storage/LocalPreviewStorage.php +++ b/lib/private/Preview/Storage/LocalPreviewStorage.php @@ -312,18 +312,17 @@ private function fetchFilecacheByFileIds(array $fileIds): array { $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)) - ); - } - $rows = $qb->runAcrossAllShards() - ->executeQuery(); - while ($row = $rows->fetchAssociative()) { - $result[(int)$row['fileid']] = $row; + $qb->setParameter('fileIds', $chunk, IQueryBuilder::PARAM_INT_ARRAY); + $rows = $qb->executeQuery(); + while ($row = $rows->fetchAssociative()) { + $result[(int)$row['fileid']] = $row; + } + $rows->closeCursor(); } - $rows->closeCursor(); return $result; } @@ -340,18 +339,17 @@ private function fetchFilecacheByPathHashes(array $pathHashes): array { $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)) - ); - } - $rows = $qb->runAcrossAllShards() - ->executeQuery(); - while ($row = $rows->fetchAssociative()) { - $result[$row['path_hash']] = $row; + $qb->setParameter('pathHashes', $chunk, IQueryBuilder::PARAM_STR_ARRAY); + $rows = $qb->executeQuery(); + while ($row = $rows->fetchAssociative()) { + $result[$row['path_hash']] = $row; + } + $rows->closeCursor(); } - $rows->closeCursor(); return $result; } diff --git a/tests/lib/Preview/Storage/LocalPreviewStorageTest.php b/tests/lib/Preview/Storage/LocalPreviewStorageTest.php index dbc3cea5342a3..14e6419a9d538 100644 --- a/tests/lib/Preview/Storage/LocalPreviewStorageTest.php +++ b/tests/lib/Preview/Storage/LocalPreviewStorageTest.php @@ -129,6 +129,7 @@ private function buildQueryBuilderMock(array $rows): IQueryBuilder&MockObject { $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);