From 62f31d67bdf7cceaf5eceecfa58f4d1f0ab4e168 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 14 Sep 2016 16:29:33 +0200 Subject: Chunk if you have too many events --- apps/dav/lib/CalDAV/CalDavBackend.php | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php index 84ec8433a83..886dcd4f6d8 100644 --- a/apps/dav/lib/CalDAV/CalDavBackend.php +++ b/apps/dav/lib/CalDAV/CalDavBackend.php @@ -616,19 +616,25 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription * @return array */ function getMultipleCalendarObjects($calendarId, array $uris) { + if (empty($uris)) { + return []; + } + + $chunks = array_chunk($uris, 100); + $result = []; + $query = $this->db->getQueryBuilder(); $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'calendardata', 'componenttype', 'classification']) - ->from('calendarobjects') - ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) - ->andWhere($query->expr()->in('uri', $query->createParameter('uri'))) - ->setParameter('uri', $uris, IQueryBuilder::PARAM_STR_ARRAY); - - $stmt = $query->execute(); + ->from('calendarobjects') + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) + ->andWhere($query->expr()->in('uri', $query->createParameter('uri'))); - $result = []; - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { + foreach ($chunks as $uris) { + $query->setParameter('uri', $uris, IQueryBuilder::PARAM_STR_ARRAY); + $stmt = $query->execute(); - $result[] = [ + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { + $result[] = [ 'id' => $row['id'], 'uri' => $row['uri'], 'lastmodified' => $row['lastmodified'], @@ -638,8 +644,8 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription 'calendardata' => $this->readBlob($row['calendardata']), 'component' => strtolower($row['componenttype']), 'classification' => (int)$row['classification'] - ]; - + ]; + } } return $result; } -- cgit v1.2.3 From 08c6ca5a1a97d358a6aea9ce87ba8c8579be42c2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 14 Sep 2016 16:29:58 +0200 Subject: 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 b8491c08ff6..f7e0a017803 100644 --- a/apps/dav/lib/CardDAV/CardDavBackend.php +++ b/apps/dav/lib/CardDAV/CardDavBackend.php @@ -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; } -- cgit v1.2.3 From 44fbf6f7349ed4be30cba0957bb1c308a895d232 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 15 Sep 2016 09:47:39 +0200 Subject: Close cursors --- apps/dav/lib/CalDAV/CalDavBackend.php | 11 ++++++----- apps/dav/lib/CardDAV/CardDavBackend.php | 3 ++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php index 886dcd4f6d8..17479c490a9 100644 --- a/apps/dav/lib/CalDAV/CalDavBackend.php +++ b/apps/dav/lib/CalDAV/CalDavBackend.php @@ -621,7 +621,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription } $chunks = array_chunk($uris, 100); - $result = []; + $objects = []; $query = $this->db->getQueryBuilder(); $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'calendardata', 'componenttype', 'classification']) @@ -631,10 +631,10 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription foreach ($chunks as $uris) { $query->setParameter('uri', $uris, IQueryBuilder::PARAM_STR_ARRAY); - $stmt = $query->execute(); + $result = $query->execute(); - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { - $result[] = [ + while ($row = $result->fetch()) { + $objects[] = [ 'id' => $row['id'], 'uri' => $row['uri'], 'lastmodified' => $row['lastmodified'], @@ -646,8 +646,9 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription 'classification' => (int)$row['classification'] ]; } + $result->closeCursor(); } - return $result; + return $objects; } /** diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php index f7e0a017803..3aab2712125 100644 --- a/apps/dav/lib/CardDAV/CardDavBackend.php +++ b/apps/dav/lib/CardDAV/CardDavBackend.php @@ -499,11 +499,12 @@ class CardDavBackend implements BackendInterface, SyncSupport { $query->setParameter('uri', $uris, IQueryBuilder::PARAM_STR_ARRAY); $result = $query->execute(); - while($row = $result->fetch()) { + while ($row = $result->fetch()) { $row['etag'] = '"' . $row['etag'] . '"'; $row['carddata'] = $this->readBlob($row['carddata']); $cards[] = $row; } + $result->closeCursor(); } return $cards; } -- cgit v1.2.3