summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2016-09-16 10:12:30 +0200
committerGitHub <noreply@github.com>2016-09-16 10:12:30 +0200
commitfcc91cbc494836766b545c320fe4c22e02579ec8 (patch)
tree46c40f8644d54f2fedb2ab10860000c9b7a6724c /apps
parent9fa288f12b7bf29ba2812f93f65dfcac62d1ea75 (diff)
parent44fbf6f7349ed4be30cba0957bb1c308a895d232 (diff)
downloadnextcloud-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.php31
-rw-r--r--apps/dav/lib/CardDAV/CardDavBackend.php27
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;
}