Chunk if you have too many events

This commit is contained in:
Joas Schilling 2016-09-14 16:29:33 +02:00
parent e60d5d08e0
commit 33c39f7b27
No known key found for this signature in database
GPG Key ID: E166FD8976B3BAC8
1 changed files with 17 additions and 11 deletions

View File

@ -567,19 +567,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);
->from('calendarobjects')
->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId)))
->andWhere($query->expr()->in('uri', $query->createParameter('uri')));
$stmt = $query->execute();
foreach ($chunks as $uris) {
$query->setParameter('uri', $uris, IQueryBuilder::PARAM_STR_ARRAY);
$stmt = $query->execute();
$result = [];
while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$result[] = [
while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$result[] = [
'id' => $row['id'],
'uri' => $row['uri'],
'lastmodified' => $row['lastmodified'],
@ -589,8 +595,8 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
'calendardata' => $this->readBlob($row['calendardata']),
'component' => strtolower($row['componenttype']),
'classification' => (int)$row['classification']
];
];
}
}
return $result;
}