Skip to content

Commit

Permalink
Merge pull request #31552 from nextcloud/backport/31274/stable22
Browse files Browse the repository at this point in the history
[stable22] Fix more than 1000 entries in queries exception in CardDavBackend
  • Loading branch information
blizzz committed Mar 16, 2022
2 parents 85733a4 + 04ad3ba commit 00e9436
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions apps/dav/lib/CardDAV/CardDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public function getAddressBooksForUserCount($principalUri) {
->from('addressbooks')
->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri)));

$result = $query->execute();
$result = $query->executeQuery();
$column = (int) $result->fetchOne();
$result->closeCursor();
return $column;
Expand Down Expand Up @@ -1130,15 +1130,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->executeQuery();
$cards = array_merge($cards, $result->fetchAll());
$result->closeCursor();
}

return array_map(function ($array) {
$array['addressbookid'] = (int) $array['addressbookid'];
Expand Down

0 comments on commit 00e9436

Please sign in to comment.