Chunk if you have too many contacts

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

View File

@ -482,23 +482,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;
}