From 09c36839ae2d56ea5f1abaaaec2fd83b01eb9bda Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Fri, 10 Jun 2022 15:11:00 +1000 Subject: [PATCH 1/3] refresh query duration handling --- .../ProvidesDefaultConfigurationOptions.php | 1 + .../RefreshQueryDurationHandling.php | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/Listeners/RefreshQueryDurationHandling.php diff --git a/src/Concerns/ProvidesDefaultConfigurationOptions.php b/src/Concerns/ProvidesDefaultConfigurationOptions.php index d0590c46e..0eb049196 100644 --- a/src/Concerns/ProvidesDefaultConfigurationOptions.php +++ b/src/Concerns/ProvidesDefaultConfigurationOptions.php @@ -47,6 +47,7 @@ public static function prepareApplicationForNextOperation(): array \Laravel\Octane\Listeners\GiveNewApplicationInstanceToViewFactory::class, \Laravel\Octane\Listeners\FlushDatabaseRecordModificationState::class, \Laravel\Octane\Listeners\FlushDatabaseQueryLog::class, + \Laravel\Octane\Listeners\RefreshQueryDurationHandling::class, \Laravel\Octane\Listeners\FlushLogContext::class, \Laravel\Octane\Listeners\FlushArrayCache::class, \Laravel\Octane\Listeners\FlushMonologState::class, diff --git a/src/Listeners/RefreshQueryDurationHandling.php b/src/Listeners/RefreshQueryDurationHandling.php new file mode 100644 index 000000000..ffe654cb7 --- /dev/null +++ b/src/Listeners/RefreshQueryDurationHandling.php @@ -0,0 +1,25 @@ +sandbox->resolved('db')) { + return; + } + + foreach ($event->sandbox->make('db')->getConnections() as $connection) { + $connection->resetTotalQueryDuration(); + + $connection->restoreAlreadyRunQueryDurationHandlers(); + } + } +} From 936c817a56ce1886ba550dca5b1368c14fac4876 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Thu, 23 Jun 2022 16:21:24 +1000 Subject: [PATCH 2/3] adjust naming --- src/Listeners/RefreshQueryDurationHandling.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Listeners/RefreshQueryDurationHandling.php b/src/Listeners/RefreshQueryDurationHandling.php index ffe654cb7..f0af509d5 100644 --- a/src/Listeners/RefreshQueryDurationHandling.php +++ b/src/Listeners/RefreshQueryDurationHandling.php @@ -19,7 +19,7 @@ public function handle($event): void foreach ($event->sandbox->make('db')->getConnections() as $connection) { $connection->resetTotalQueryDuration(); - $connection->restoreAlreadyRunQueryDurationHandlers(); + $connection->allowQueryDurationHandlersToRunAgain(); } } } From 0ff370e8948f24c5e51b77c6acd32ef500fa6ad2 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Thu, 23 Jun 2022 16:31:22 +1000 Subject: [PATCH 3/3] ensure only called when methods exist --- src/Listeners/RefreshQueryDurationHandling.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Listeners/RefreshQueryDurationHandling.php b/src/Listeners/RefreshQueryDurationHandling.php index f0af509d5..78f98427d 100644 --- a/src/Listeners/RefreshQueryDurationHandling.php +++ b/src/Listeners/RefreshQueryDurationHandling.php @@ -17,9 +17,13 @@ public function handle($event): void } foreach ($event->sandbox->make('db')->getConnections() as $connection) { - $connection->resetTotalQueryDuration(); - - $connection->allowQueryDurationHandlersToRunAgain(); + if ( + method_exists($connection, 'resetTotalQueryDuration') + && method_exists($connection, 'allowQueryDurationHandlersToRunAgain') + ) { + $connection->resetTotalQueryDuration(); + $connection->allowQueryDurationHandlersToRunAgain(); + } } } }