From 5b8c7768b1dca001f78c1fb7251c29e781677136 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 14 Sep 2016 16:29:58 +0200 Subject: [PATCH] Chunk if you have too many contacts --- apps/dav/lib/CardDAV/CardDavBackend.php | 26 +++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php index f8552f1323e..ac0b5849f8a 100644 --- a/apps/dav/lib/CardDAV/CardDavBackend.php +++ b/apps/dav/lib/CardDAV/CardDavBackend.php @@ -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; } -- 2.39.5