aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/Migration/BuildCalendarSearchIndexBackgroundJob.php
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2020-08-20 07:56:25 +0200
committerJoas Schilling <coding@schilljs.com>2020-08-20 07:56:25 +0200
commit553cda2a6d3f89d1844c8abfbd8f5a125b9ae349 (patch)
tree8e1f30fbf20c7ecf002fb6ce50f6453c03b6197f /apps/dav/lib/Migration/BuildCalendarSearchIndexBackgroundJob.php
parent6d21e0f6ff1932125931a8a7e8c9dd76594e2431 (diff)
downloadnextcloud-server-553cda2a6d3f89d1844c8abfbd8f5a125b9ae349.tar.gz
nextcloud-server-553cda2a6d3f89d1844c8abfbd8f5a125b9ae349.zip
Don't load all calendar objects into memory
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/dav/lib/Migration/BuildCalendarSearchIndexBackgroundJob.php')
-rw-r--r--apps/dav/lib/Migration/BuildCalendarSearchIndexBackgroundJob.php29
1 files changed, 15 insertions, 14 deletions
diff --git a/apps/dav/lib/Migration/BuildCalendarSearchIndexBackgroundJob.php b/apps/dav/lib/Migration/BuildCalendarSearchIndexBackgroundJob.php
index ada3c470171..5f6ec2e77f2 100644
--- a/apps/dav/lib/Migration/BuildCalendarSearchIndexBackgroundJob.php
+++ b/apps/dav/lib/Migration/BuildCalendarSearchIndexBackgroundJob.php
@@ -69,12 +69,18 @@ class BuildCalendarSearchIndexBackgroundJob extends QueuedJob {
}
public function run($arguments) {
- $offset = $arguments['offset'];
- $stopAt = $arguments['stopAt'];
+ $offset = (int) $arguments['offset'];
+ $stopAt = (int) $arguments['stopAt'];
$this->logger->info('Building calendar index (' . $offset .'/' . $stopAt . ')');
- $offset = $this->buildIndex($offset, $stopAt);
+ $startTime = $this->timeFactory->getTime();
+ while (($this->timeFactory->getTime() - $startTime) < 15) {
+ $offset = $this->buildIndex($offset, $stopAt);
+ if ($offset >= $stopAt) {
+ break;
+ }
+ }
if ($offset >= $stopAt) {
$this->logger->info('Building calendar index done');
@@ -92,18 +98,17 @@ class BuildCalendarSearchIndexBackgroundJob extends QueuedJob {
* @param int $stopAt
* @return int
*/
- private function buildIndex($offset, $stopAt) {
- $startTime = $this->timeFactory->getTime();
-
+ private function buildIndex(int $offset, int $stopAt): int {
$query = $this->db->getQueryBuilder();
$query->select(['id', 'calendarid', 'uri', 'calendardata'])
->from('calendarobjects')
->where($query->expr()->lte('id', $query->createNamedParameter($stopAt)))
->andWhere($query->expr()->gt('id', $query->createNamedParameter($offset)))
- ->orderBy('id', 'ASC');
+ ->orderBy('id', 'ASC')
+ ->setMaxResults(500);
- $stmt = $query->execute();
- while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
+ $result = $query->execute();
+ while ($row = $result->fetch(\PDO::FETCH_ASSOC)) {
$offset = $row['id'];
$calendarData = $row['calendardata'];
@@ -112,12 +117,8 @@ class BuildCalendarSearchIndexBackgroundJob extends QueuedJob {
}
$this->calDavBackend->updateProperties($row['calendarid'], $row['uri'], $calendarData);
-
- if (($this->timeFactory->getTime() - $startTime) > 15) {
- return $offset;
- }
}
- return $stopAt;
+ return $offset;
}
}