]> source.dussan.org Git - nextcloud-server.git/commitdiff
Chunk if you have too many contacts
authorJoas Schilling <coding@schilljs.com>
Wed, 14 Sep 2016 14:29:58 +0000 (16:29 +0200)
committerJoas Schilling <coding@schilljs.com>
Thu, 29 Sep 2016 12:33:44 +0000 (14:33 +0200)
apps/dav/lib/CardDAV/CardDavBackend.php

index f8552f1323e113cdafc20382de0c1bad01f257e4..ac0b5849f8a12c608462f87a751397051e669942 100644 (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;
        }