Skip to content

Commit 00e9436

Browse files
authored
Merge pull request #31552 from nextcloud/backport/31274/stable22
[stable22] Fix more than 1000 entries in queries exception in CardDavBackend
2 parents 85733a4 + 04ad3ba commit 00e9436

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

apps/dav/lib/CardDAV/CardDavBackend.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public function getAddressBooksForUserCount($principalUri) {
139139
->from('addressbooks')
140140
->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri)));
141141

142-
$result = $query->execute();
142+
$result = $query->executeQuery();
143143
$column = (int) $result->fetchOne();
144144
$result->closeCursor();
145145
return $column;
@@ -1130,15 +1130,18 @@ private function searchByAddressBookIds(array $addressBookIds,
11301130
return (int)$match['cardid'];
11311131
}, $matches);
11321132

1133+
$cards = [];
11331134
$query = $this->db->getQueryBuilder();
11341135
$query->select('c.addressbookid', 'c.carddata', 'c.uri')
11351136
->from($this->dbCardsTable, 'c')
1136-
->where($query->expr()->in('c.id', $query->createNamedParameter($matches, IQueryBuilder::PARAM_INT_ARRAY)));
1137-
1138-
$result = $query->execute();
1139-
$cards = $result->fetchAll();
1137+
->where($query->expr()->in('c.id', $query->createParameter('matches')));
11401138

1141-
$result->closeCursor();
1139+
foreach (array_chunk($matches, 1000) as $matchesChunk) {
1140+
$query->setParameter('matches', $matchesChunk, IQueryBuilder::PARAM_INT_ARRAY);
1141+
$result = $query->executeQuery();
1142+
$cards = array_merge($cards, $result->fetchAll());
1143+
$result->closeCursor();
1144+
}
11421145

11431146
return array_map(function ($array) {
11441147
$array['addressbookid'] = (int) $array['addressbookid'];

0 commit comments

Comments
 (0)