From f2b9d856b9bf5cf1b96c68a455c15cea2ad46fd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Debrauwer?= Date: Fri, 29 Nov 2024 21:34:14 +0100 Subject: [PATCH] [1.x] Prevent memory leak on `pulse:check` command when using Telescope (#426) * Prevent memory leak * Fix * formatting --------- Co-authored-by: Taylor Otwell --- phpstan.neon.dist | 3 +++ src/Commands/CheckCommand.php | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 20b7cf94..7c566f3c 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -2,3 +2,6 @@ parameters: paths: - src level: 8 + ignoreErrors: + - "#Class Laravel\\\\Telescope\\\\Contracts\\\\EntriesRepository not found#" + - "#Call to static method store\\(\\) on an unknown class Laravel\\\\Telescope\\\\Telescope#" diff --git a/src/Commands/CheckCommand.php b/src/Commands/CheckCommand.php index 004bc7ae..fb08957e 100644 --- a/src/Commands/CheckCommand.php +++ b/src/Commands/CheckCommand.php @@ -68,6 +68,8 @@ public function handle( $pulse->ingest(); + $this->ensureTelescopeEntriesAreCollected(); + if ($isVapor || $this->option('once')) { return self::SUCCESS; } @@ -75,4 +77,14 @@ public function handle( Sleep::until($now->addSecond()); } } + + /** + * Schedule Telescope to store entries if enabled. + */ + protected function ensureTelescopeEntriesAreCollected(): void + { + if ($this->laravel->bound(\Laravel\Telescope\Contracts\EntriesRepository::class)) { + \Laravel\Telescope\Telescope::store($this->laravel->make(\Laravel\Telescope\Contracts\EntriesRepository::class)); + } + } }