From 0df508d880b5823613dadc6bb46f781b32084a27 Mon Sep 17 00:00:00 2001 From: Arunas Skirius Date: Wed, 21 Jun 2023 08:12:54 +0300 Subject: [PATCH 1/2] potential fix for Octane inconsistent state --- src/LogReader.php | 5 +++++ src/LogViewerServiceProvider.php | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/LogReader.php b/src/LogReader.php index 711910d7..0ee4407e 100644 --- a/src/LogReader.php +++ b/src/LogReader.php @@ -60,6 +60,11 @@ public static function clearInstance(LogFile $file): void } } + public static function clearInstances(): void + { + self::$_instances = []; + } + public function index(): LogIndex { return $this->file->index($this->query); diff --git a/src/LogViewerServiceProvider.php b/src/LogViewerServiceProvider.php index c75346a9..23647de6 100644 --- a/src/LogViewerServiceProvider.php +++ b/src/LogViewerServiceProvider.php @@ -9,6 +9,7 @@ use Illuminate\Support\Facades\Route; use Illuminate\Support\ServiceProvider; use Illuminate\Support\Str; +use Laravel\Octane\Events\RequestTerminated; use Opcodes\LogViewer\Console\Commands\GenerateDummyLogsCommand; use Opcodes\LogViewer\Console\Commands\PublishCommand; use Opcodes\LogViewer\Events\LogFileDeleted; @@ -62,6 +63,7 @@ public function boot() $this->defineAssetPublishing(); $this->defineDefaultGates(); $this->configureMiddleware(); + $this->resetStateAfterOctaneRequest(); Event::listen(LogFileDeleted::class, function (LogFileDeleted $event) { LogViewer::clearFileCache(); @@ -135,7 +137,14 @@ protected function configureMiddleware(): void $kernel->prependToMiddlewarePriority(EnsureFrontendRequestsAreStateful::class); } - private function isEnabled(): bool + protected function resetStateAfterOctaneRequest() + { + $this->app['events']->listen(RequestTerminated::class, function ($event) { + LogReader::clearInstances(); + }); + } + + protected function isEnabled(): bool { return (bool) $this->app['config']->get("{$this->name}.enabled", true); } From eb454b17418f1a9dcb7f63749109f25f22249d37 Mon Sep 17 00:00:00 2001 From: arukompas Date: Wed, 21 Jun 2023 05:13:28 +0000 Subject: [PATCH 2/2] Fix styling --- tests/Unit/LogIndex/ChunkDefinitionsTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Unit/LogIndex/ChunkDefinitionsTest.php b/tests/Unit/LogIndex/ChunkDefinitionsTest.php index 80f37776..eb5319a0 100644 --- a/tests/Unit/LogIndex/ChunkDefinitionsTest.php +++ b/tests/Unit/LogIndex/ChunkDefinitionsTest.php @@ -95,7 +95,7 @@ expect($cachedMetadata)->toHaveKey('chunk_definitions') ->and($cachedMetadata['chunk_definitions'])->toBeArray()->toHaveCount(1) ->and($cachedMetadata['chunk_definitions'][0]) - ->toBe($logIndex->getChunkDefinition(0)); + ->toBe($logIndex->getChunkDefinition(0)); // after adding a new log entry, the cache won't be updated until calling the –>save() method. $logIndex->addToIndex(3500, now(), 'info'); @@ -109,7 +109,7 @@ expect($updatedCachedMetadata)->not->toBe($cachedMetadata) ->toHaveKey('current_chunk_definition') ->and($updatedCachedMetadata['current_chunk_definition']) - ->toBe($logIndex->getChunkDefinition(1)); + ->toBe($logIndex->getChunkDefinition(1)); }); it('keeps the chunk definitions after re-instantiating the log index', function () {