Skip to content

Commit 2351fc0

Browse files
authored
Add option to hide queries (#1661)
1 parent b49a146 commit 2351fc0

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

config/debugbar.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@
214214
],
215215
'db' => [
216216
'with_params' => true, // Render SQL with the parameters substituted
217+
'exclude_paths' => [ // Paths to exclude entirely from the collector
218+
// 'vendor/laravel/framework/src/Illuminate/Session', // Exclude sessions queries
219+
],
217220
'backtrace' => true, // Use a backtrace to find the origin of the query in your files.
218221
'backtrace_exclude_paths' => [], // Paths to exclude from backtrace. (in addition to defaults)
219222
'timeline' => false, // Add the queries to the timeline

src/DataCollector/QueryCollector.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class QueryCollector extends PDOCollector
2828
protected $showHints = false;
2929
protected $showCopyButton = false;
3030
protected $reflection = [];
31+
protected $excludePaths = [];
3132
protected $backtraceExcludePaths = [
3233
'/vendor/laravel/framework/src/Illuminate/Support',
3334
'/vendor/laravel/framework/src/Illuminate/Database',
@@ -99,6 +100,11 @@ public function setFindSource($value, array $middleware)
99100
$this->middleware = $middleware;
100101
}
101102

103+
public function mergeExcludePaths(array $excludePaths)
104+
{
105+
$this->excludePaths = array_merge($this->excludePaths, $excludePaths);
106+
}
107+
102108
/**
103109
* Set additional paths to exclude from the backtrace
104110
*
@@ -491,6 +497,11 @@ public function collect()
491497
default => false,
492498
};
493499

500+
$source = $this->getDataFormatter()->formatSource($source);
501+
if (Str::startsWith($source, $this->excludePaths)) {
502+
continue;
503+
}
504+
494505
$statements[] = [
495506
'sql' => $this->getSqlQueryToDisplay($query),
496507
'type' => $query['type'],
@@ -505,7 +516,7 @@ public function collect()
505516
'memory' => $query['memory'],
506517
'memory_str' => $query['memory'] ? $this->getDataFormatter()->formatBytes($query['memory']) : null,
507518
'filename' => $this->getDataFormatter()->formatSource($source, true),
508-
'source' => $this->getDataFormatter()->formatSource($source),
519+
'source' => $source,
509520
'xdebug_link' => is_object($source) ? $this->getXdebugLink($source->file ?: '', $source->line) : null,
510521
'connection' => $connectionName,
511522
'explain' => $this->explainQuery && $canExplainQuery ? [
@@ -568,6 +579,8 @@ public function collect()
568579

569580
$data = [
570581
'nb_statements' => $this->queryCount,
582+
'nb_visible_statements' => count($statements),
583+
'nb_excluded_statements' => $this->queryCount - count($statements),
571584
'nb_failed_statements' => 0,
572585
'accumulated_duration' => $totalTime,
573586
'accumulated_duration_str' => $this->formatDuration($totalTime),
@@ -599,7 +612,7 @@ public function getWidgets()
599612
"default" => "[]"
600613
],
601614
"queries:badge" => [
602-
"map" => "queries.nb_statements",
615+
"map" => "queries.nb_visible_statements",
603616
"default" => 0
604617
]
605618
];

src/LaravelDebugbar.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,12 @@ function (\Illuminate\Log\Events\MessageLogged $log) use ($logger) {
309309
$queryCollector->setFindSource($dbBacktrace, $middleware);
310310
}
311311

312-
if ($excludePaths = $config->get('debugbar.options.db.backtrace_exclude_paths')) {
313-
$queryCollector->mergeBacktraceExcludePaths($excludePaths);
312+
if ($excludePaths = $config->get('debugbar.options.db.exclude_paths')) {
313+
$queryCollector->mergeExcludePaths($excludePaths);
314+
}
315+
316+
if ($excludeBacktracePaths = $config->get('debugbar.options.db.backtrace_exclude_paths')) {
317+
$queryCollector->mergeBacktraceExcludePaths($excludeBacktracePaths);
314318
}
315319

316320
if ($config->get('debugbar.options.db.explain.enabled')) {

src/Resources/queries/widget.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@
161161
}
162162

163163
const $text = $('<span />').text(`${data.nb_statements} statements were executed`);
164+
if (data.nb_excluded_statements) {
165+
$text.append(`, ${data.nb_excluded_statements} have been excluded`);
166+
}
164167
if (data.nb_failed_statements > 0 || this.duplicateQueries.size > 0) {
165168
const details = [];
166169
if (data.nb_failed_statements) {

0 commit comments

Comments
 (0)