Skip to content

Commit

Permalink
Merge pull request #1178 from nextcloud/feat/hardlimit-setupcheck-run…
Browse files Browse the repository at this point in the history
…time

feat: Limit SetupCheck computing time to 5 seconds
  • Loading branch information
come-nc authored Mar 12, 2024
2 parents 0be413d + 6ae3ba3 commit 43e6c1f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/SetupChecks/LogErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function run(): SetupResult {
self::LEVEL_FATAL => 0,
];
$limit = new \DateTime('7 days ago');
$startTime = microtime(true);
foreach ($logIterator as $logItem) {
if (!isset($logItem['time'])) {
continue;
Expand All @@ -70,16 +71,20 @@ public function run(): SetupResult {
break;
}
$count[$logItem['level']]++;
if (microtime(true) > $startTime + 5) {
$limit = $time;
break;
}
}
if (array_sum($count) === 0) {
return SetupResult::success($this->l10n->t('No errors in the logs since %s', $this->dateFormatter->formatDate($limit)));
return SetupResult::success($this->l10n->t('No errors in the logs since %s', $this->dateFormatter->formatDateTime($limit)));
} elseif ($count[self::LEVEL_ERROR] + $count[self::LEVEL_FATAL] > 0) {
return SetupResult::warning(
$this->l10n->n(
'%n error in the logs since %s',
'%n errors in the logs since %s',
$count[self::LEVEL_ERROR] + $count[self::LEVEL_FATAL],
[$this->dateFormatter->formatDate($limit)],
[$this->dateFormatter->formatDateTime($limit)],
)
);
} else {
Expand All @@ -88,7 +93,7 @@ public function run(): SetupResult {
'%n warning in the logs since %s',
'%n warnings in the logs since %s'.json_encode($count),
$count[self::LEVEL_WARNING],
[$this->dateFormatter->formatDate($limit)],
[$this->dateFormatter->formatDateTime($limit)],
)
);
}
Expand Down

0 comments on commit 43e6c1f

Please sign in to comment.