Skip to content

Commit 160e074

Browse files
MatTheCatostrolucky
authored andcommitted
Display whether a query ran on a primary or replica in the profiler
1 parent cf306a7 commit 160e074

3 files changed

Lines changed: 11 additions & 2 deletions

File tree

config/middlewares.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
->args([
3434
service('doctrine.debug_data_holder'),
3535
service('debug.stopwatch')->nullOnInvalid(),
36+
service('doctrine'),
3637
])
3738

3839
->set('doctrine.dbal.idle_connection_middleware', IdleConnectionMiddleware::class)

src/Middleware/DebugMiddleware.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Doctrine\DBAL\Driver as DriverInterface;
88
use Doctrine\DBAL\Driver\Middleware;
9+
use Doctrine\Persistence\ConnectionRegistry;
910
use Symfony\Bridge\Doctrine\Middleware\Debug\DebugDataHolder;
1011
use Symfony\Bridge\Doctrine\Middleware\Debug\Driver;
1112
use Symfony\Component\Stopwatch\Stopwatch;
@@ -17,6 +18,7 @@ class DebugMiddleware implements Middleware, ConnectionNameAwareInterface
1718
public function __construct(
1819
private readonly DebugDataHolder $debugDataHolder,
1920
private readonly Stopwatch|null $stopwatch,
21+
private readonly ConnectionRegistry|null $connectionRegistry = null,
2022
) {
2123
}
2224

@@ -27,6 +29,6 @@ public function setConnectionName(string $name): void
2729

2830
public function wrap(DriverInterface $driver): DriverInterface
2931
{
30-
return new Driver($driver, $this->debugDataHolder, $this->stopwatch, $this->connectionName);
32+
return new Driver($driver, $this->debugDataHolder, $this->stopwatch, $this->connectionName, $this->connectionRegistry);
3133
}
3234
}

templates/Collector/db.html.twig

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,13 @@
227227
<td class="nowrap">{{ query.count }}</td>
228228
{% else %}
229229
<td class="nowrap">{{ loop.index }}</td>
230-
<td class="nowrap">{{ '%0.2f'|format(query.executionMS * 1000) }}&nbsp;ms</td>
230+
<td>
231+
<span class="nowrap">{{ '%0.2f'|format(query.executionMS * 1000) }}&nbsp;ms</span>
232+
{% if query.ranOnPrimary is defined and query.ranOnPrimary is not null %}
233+
<br />
234+
<span class="badge">{{ query.ranOnPrimary ? 'Primary' : 'Replica' }}</span>
235+
{% endif %}
236+
</td>
231237
{% endif %}
232238
<td>
233239
{{ query.sql|doctrine_prettify_sql }}

0 commit comments

Comments
 (0)