Skip to content

Commit 4cc7c1a

Browse files
authored
Refresh query duration handling (#541)
* refresh query duration handling * adjust naming * ensure only called when methods exist
1 parent edde78b commit 4cc7c1a

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/Concerns/ProvidesDefaultConfigurationOptions.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public static function prepareApplicationForNextOperation(): array
4747
\Laravel\Octane\Listeners\GiveNewApplicationInstanceToViewFactory::class,
4848
\Laravel\Octane\Listeners\FlushDatabaseRecordModificationState::class,
4949
\Laravel\Octane\Listeners\FlushDatabaseQueryLog::class,
50+
\Laravel\Octane\Listeners\RefreshQueryDurationHandling::class,
5051
\Laravel\Octane\Listeners\FlushLogContext::class,
5152
\Laravel\Octane\Listeners\FlushArrayCache::class,
5253
\Laravel\Octane\Listeners\FlushMonologState::class,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Laravel\Octane\Listeners;
4+
5+
class RefreshQueryDurationHandling
6+
{
7+
/**
8+
* Handle the event.
9+
*
10+
* @param mixed $event
11+
* @return void
12+
*/
13+
public function handle($event): void
14+
{
15+
if (! $event->sandbox->resolved('db')) {
16+
return;
17+
}
18+
19+
foreach ($event->sandbox->make('db')->getConnections() as $connection) {
20+
if (
21+
method_exists($connection, 'resetTotalQueryDuration')
22+
&& method_exists($connection, 'allowQueryDurationHandlersToRunAgain')
23+
) {
24+
$connection->resetTotalQueryDuration();
25+
$connection->allowQueryDurationHandlersToRunAgain();
26+
}
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)