Skip to content

Commit

Permalink
Merge pull request #31274 from nextcloud/fix/carddav-backend-1000-ora…
Browse files Browse the repository at this point in the history
…che1
  • Loading branch information
skjnldsv authored Mar 11, 2022
2 parents bcb1fc5 + 2cdaa28 commit 5ad55fa
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 5ad55fa

Please sign in to comment.