Skip to content

Commit

Permalink
Refresh query duration handling (#541)
Browse files Browse the repository at this point in the history
* refresh query duration handling

* adjust naming

* ensure only called when methods exist
  • Loading branch information
timacdonald authored Jun 23, 2022
1 parent edde78b commit 4cc7c1a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Concerns/ProvidesDefaultConfigurationOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
29 changes: 29 additions & 0 deletions src/Listeners/RefreshQueryDurationHandling.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Laravel\Octane\Listeners;

class RefreshQueryDurationHandling
{
/**
* Handle the event.
*
* @param mixed $event
* @return void
*/
public function handle($event): void
{
if (! $event->sandbox->resolved('db')) {
return;
}

foreach ($event->sandbox->make('db')->getConnections() as $connection) {
if (
method_exists($connection, 'resetTotalQueryDuration')
&& method_exists($connection, 'allowQueryDurationHandlersToRunAgain')
) {
$connection->resetTotalQueryDuration();
$connection->allowQueryDurationHandlersToRunAgain();
}
}
}
}

0 comments on commit 4cc7c1a

Please sign in to comment.