Merge pull request #1574 from nextcloud/backport-1408-chunk-calendar-objects-query
[stable10] Chunk events/contacts when getting them
This commit is contained in:
commit
ea5b522329
|
@ -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);
|
||||
$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);
|
||||
->andWhere($query->expr()->in('uri', $query->createParameter('uri')));
|
||||
|
||||
$stmt = $query->execute();
|
||||
foreach ($chunks as $uris) {
|
||||
$query->setParameter('uri', $uris, IQueryBuilder::PARAM_STR_ARRAY);
|
||||
$result = $query->execute();
|
||||
|
||||
$result = [];
|
||||
while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
|
||||
$result[] = [
|
||||
while ($row = $result->fetch()) {
|
||||
$objects[] = [
|
||||
'id' => $row['id'],
|
||||
'uri' => $row['uri'],
|
||||
'lastmodified' => $row['lastmodified'],
|
||||
|
@ -590,9 +596,10 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
|
|||
'component' => strtolower($row['componenttype']),
|
||||
'classification' => (int)$row['classification']
|
||||
];
|
||||
|
||||
}
|
||||
return $result;
|
||||
$result->closeCursor();
|
||||
}
|
||||
return $objects;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -439,23 +439,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);
|
||||
|
||||
$cards = [];
|
||||
->andWhere($query->expr()->in('uri', $query->createParameter('uri')));
|
||||
|
||||
foreach ($chunks as $uris) {
|
||||
$query->setParameter('uri', $uris, IQueryBuilder::PARAM_STR_ARRAY);
|
||||
$result = $query->execute();
|
||||
|
||||
while ($row = $result->fetch()) {
|
||||
$row['etag'] = '"' . $row['etag'] . '"';
|
||||
$row['carddata'] = $this->readBlob($row['carddata']);
|
||||
$cards[] = $row;
|
||||
}
|
||||
$result->closeCursor();
|
||||
|
||||
}
|
||||
return $cards;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue