Skip to content

Commit

Permalink
Merge pull request #31551 from nextcloud/backport/31274/stable21
Browse files Browse the repository at this point in the history
[stable21] Fix more than 1000 entries in queries exception in CardDavBackend
  • Loading branch information
blizzz authored Mar 21, 2022
2 parents 5890c04 + 8e69237 commit d023ece
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions apps/dav/lib/CardDAV/CardDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -1110,15 +1110,18 @@ private function searchByAddressBookIds(array $addressBookIds,
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'];
Expand Down

0 comments on commit d023ece

Please sign in to comment.