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,18 +567,24 @@ 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);
->andWhere($query->expr()->in('uri', $query->createParameter('uri')));
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'],
@ -590,7 +596,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
'component' => strtolower($row['componenttype']),
'classification' => (int)$row['classification']
];
}
}
return $result;
}