Skip to content

Commit

Permalink
Merge pull request #235 from opcodesio/octane-fix
Browse files Browse the repository at this point in the history
potential fix for Octane inconsistent state
  • Loading branch information
arukompas authored Jun 21, 2023
2 parents 20b547a + eb454b1 commit 5ed339d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/LogReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 10 additions & 1 deletion src/LogViewerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -62,6 +63,7 @@ public function boot()
$this->defineAssetPublishing();
$this->defineDefaultGates();
$this->configureMiddleware();
$this->resetStateAfterOctaneRequest();

Event::listen(LogFileDeleted::class, function (LogFileDeleted $event) {
LogViewer::clearFileCache();
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/LogIndex/ChunkDefinitionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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 () {
Expand Down

0 comments on commit 5ed339d

Please sign in to comment.