From 7af84d9ae3c78bea06ee7db174244726c88b6825 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 11 Mar 2024 11:20:53 +0100 Subject: [PATCH 1/2] feat: Limit SetupCheck computing time to 5 seconds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In case of early stop, it will show in the output since when was the number of errors or warnings counted. Also added time to the output in case the date is today. Signed-off-by: Côme Chilliet --- lib/SetupChecks/LogErrors.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/SetupChecks/LogErrors.php b/lib/SetupChecks/LogErrors.php index 6681ebac..51a6849e 100644 --- a/lib/SetupChecks/LogErrors.php +++ b/lib/SetupChecks/LogErrors.php @@ -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; @@ -70,16 +71,23 @@ public function run(): SetupResult { break; } $count[$logItem['level']]++; + if (microtime(true) > $startTime + 5) { + echo $logItem['time']."\n"; + echo $this->dateFormatter->formatDate($time)."\n"; + echo $this->dateFormatter->formatDateTime($time)."\n"; + $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 { @@ -88,7 +96,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)], ) ); } From 6ae3ba3cb487003e7f9764163e3f35949a5bb263 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 11 Mar 2024 16:35:08 +0100 Subject: [PATCH 2/2] fixup! feat: Limit SetupCheck computing time to 5 seconds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- lib/SetupChecks/LogErrors.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/SetupChecks/LogErrors.php b/lib/SetupChecks/LogErrors.php index 51a6849e..1d8a228c 100644 --- a/lib/SetupChecks/LogErrors.php +++ b/lib/SetupChecks/LogErrors.php @@ -72,9 +72,6 @@ public function run(): SetupResult { } $count[$logItem['level']]++; if (microtime(true) > $startTime + 5) { - echo $logItem['time']."\n"; - echo $this->dateFormatter->formatDate($time)."\n"; - echo $this->dateFormatter->formatDateTime($time)."\n"; $limit = $time; break; }