Chunk if you have too many contacts

This commit is contained in:
Joas Schilling 2016-09-14 16:29:58 +02:00
parent 33c39f7b27
commit 5b8c7768b1
No known key found for this signature in database
GPG Key ID: E166FD8976B3BAC8
1 changed files with 16 additions and 10 deletions

View File

@ -439,23 +439,29 @@ class CardDavBackend implements BackendInterface, SyncSupport {
* @return array
*/
function getMultipleCards($addressBookId, array $uris) {
if (empty($uris)) {
return [];
}
$chunks = array_chunk($uris, 100);
$cards = [];
$query = $this->db->getQueryBuilder();
$query->select(['id', 'uri', 'lastmodified', 'etag', 'size', 'carddata'])
->from('cards')
->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId)))
->andWhere($query->expr()->in('uri', $query->createParameter('uri')))
->setParameter('uri', $uris, IQueryBuilder::PARAM_STR_ARRAY);
->andWhere($query->expr()->in('uri', $query->createParameter('uri')));
$cards = [];
foreach ($chunks as $uris) {
$query->setParameter('uri', $uris, IQueryBuilder::PARAM_STR_ARRAY);
$result = $query->execute();
$result = $query->execute();
while($row = $result->fetch()) {
$row['etag'] = '"' . $row['etag'] . '"';
$row['carddata'] = $this->readBlob($row['carddata']);
$cards[] = $row;
while($row = $result->fetch()) {
$row['etag'] = '"' . $row['etag'] . '"';
$row['carddata'] = $this->readBlob($row['carddata']);
$cards[] = $row;
}
}
$result->closeCursor();
return $cards;
}