diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2016-09-16 10:12:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-16 10:12:30 +0200 |
commit | fcc91cbc494836766b545c320fe4c22e02579ec8 (patch) | |
tree | 46c40f8644d54f2fedb2ab10860000c9b7a6724c /apps | |
parent | 9fa288f12b7bf29ba2812f93f65dfcac62d1ea75 (diff) | |
parent | 44fbf6f7349ed4be30cba0957bb1c308a895d232 (diff) | |
download | nextcloud-server-fcc91cbc494836766b545c320fe4c22e02579ec8.tar.gz nextcloud-server-fcc91cbc494836766b545c320fe4c22e02579ec8.zip |
Merge pull request #1408 from nextcloud/chunk-calendar-objects-query
Chunk if you have too many contacts/events
Diffstat (limited to 'apps')
-rw-r--r-- | apps/dav/lib/CalDAV/CalDavBackend.php | 31 | ||||
-rw-r--r-- | apps/dav/lib/CardDAV/CardDavBackend.php | 27 |
2 files changed, 36 insertions, 22 deletions
diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php index 84ec8433a83..17479c490a9 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); + $objects = []; + $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); + $result = $query->execute(); - $result[] = [ + while ($row = $result->fetch()) { + $objects[] = [ 'id' => $row['id'], 'uri' => $row['uri'], 'lastmodified' => $row['lastmodified'], @@ -638,10 +644,11 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription 'calendardata' => $this->readBlob($row['calendardata']), 'component' => strtolower($row['componenttype']), '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 b8491c08ff6..3aab2712125 100644 --- a/apps/dav/lib/CardDAV/CardDavBackend.php +++ b/apps/dav/lib/CardDAV/CardDavBackend.php @@ -482,23 +482,30 @@ 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(); } - $result->closeCursor(); - return $cards; } |