Merge pull request #31551 from nextcloud/backport/31274/stable21

[stable21] Fix more than 1000 entries in queries exception in CardDavBackend
pull/31670/head
blizzz 2022-03-21 19:33:46 +07:00 committed by GitHub
commit d023ecee6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 5 deletions

@ -1110,15 +1110,18 @@ class CardDavBackend implements BackendInterface, SyncSupport {
return (int)$match['cardid'];
}, $matches);
$cards = [];
$query = $this->db->getQueryBuilder();
$query->select('c.addressbookid', 'c.carddata', 'c.uri')
->from($this->dbCardsTable, 'c')
->where($query->expr()->in('c.id', $query->createNamedParameter($matches, IQueryBuilder::PARAM_INT_ARRAY)));
$result = $query->execute();
$cards = $result->fetchAll();
->where($query->expr()->in('c.id', $query->createParameter('matches')));
$result->closeCursor();
foreach (array_chunk($matches, 1000) as $matchesChunk) {
$query->setParameter('matches', $matchesChunk, IQueryBuilder::PARAM_INT_ARRAY);
$result = $query->execute();
$cards = array_merge($cards, $result->fetchAll());
$result->closeCursor();
}
return array_map(function ($array) {
$array['addressbookid'] = (int) $array['addressbookid'];