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 * @return array
*/ */
function getMultipleCalendarObjects($calendarId, array $uris) { function getMultipleCalendarObjects($calendarId, array $uris) {
if (empty($uris)) {
return [];
}
$chunks = array_chunk($uris, 100);
$result = [];
$query = $this->db->getQueryBuilder(); $query = $this->db->getQueryBuilder();
$query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'calendardata', 'componenttype', 'classification']) $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'calendardata', 'componenttype', 'classification'])
->from('calendarobjects') ->from('calendarobjects')
->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId)))
->andWhere($query->expr()->in('uri', $query->createParameter('uri'))) ->andWhere($query->expr()->in('uri', $query->createParameter('uri')));
->setParameter('uri', $uris, IQueryBuilder::PARAM_STR_ARRAY);
$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)) {
while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { $result[] = [
$result[] = [
'id' => $row['id'], 'id' => $row['id'],
'uri' => $row['uri'], 'uri' => $row['uri'],
'lastmodified' => $row['lastmodified'], 'lastmodified' => $row['lastmodified'],
@ -589,8 +595,8 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
'calendardata' => $this->readBlob($row['calendardata']), 'calendardata' => $this->readBlob($row['calendardata']),
'component' => strtolower($row['componenttype']), 'component' => strtolower($row['componenttype']),
'classification' => (int)$row['classification'] 'classification' => (int)$row['classification']
]; ];
}
} }
return $result; return $result;
} }