Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/debugbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@
],
'db' => [
'with_params' => true, // Render SQL with the parameters substituted
'exclude_paths' => [ // Paths to exclude entirely from the collector
// 'vendor/laravel/framework/src/Illuminate/Session', // Exclude sessions queries
],
'backtrace' => true, // Use a backtrace to find the origin of the query in your files.
'backtrace_exclude_paths' => [], // Paths to exclude from backtrace. (in addition to defaults)
'timeline' => false, // Add the queries to the timeline
Expand Down
17 changes: 15 additions & 2 deletions src/DataCollector/QueryCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class QueryCollector extends PDOCollector
protected $showHints = false;
protected $showCopyButton = false;
protected $reflection = [];
protected $excludePaths = [];
protected $backtraceExcludePaths = [
'/vendor/laravel/framework/src/Illuminate/Support',
'/vendor/laravel/framework/src/Illuminate/Database',
Expand Down Expand Up @@ -99,6 +100,11 @@ public function setFindSource($value, array $middleware)
$this->middleware = $middleware;
}

public function mergeExcludePaths(array $excludePaths)
{
$this->excludePaths = array_merge($this->excludePaths, $excludePaths);
}

/**
* Set additional paths to exclude from the backtrace
*
Expand Down Expand Up @@ -491,6 +497,11 @@ public function collect()
default => false,
};

$source = $this->getDataFormatter()->formatSource($source);
if (Str::startsWith($source, $this->excludePaths)) {
continue;
}

$statements[] = [
'sql' => $this->getSqlQueryToDisplay($query),
'type' => $query['type'],
Expand All @@ -505,7 +516,7 @@ public function collect()
'memory' => $query['memory'],
'memory_str' => $query['memory'] ? $this->getDataFormatter()->formatBytes($query['memory']) : null,
'filename' => $this->getDataFormatter()->formatSource($source, true),
'source' => $this->getDataFormatter()->formatSource($source),
'source' => $source,
'xdebug_link' => is_object($source) ? $this->getXdebugLink($source->file ?: '', $source->line) : null,
'connection' => $connectionName,
'explain' => $this->explainQuery && $canExplainQuery ? [
Expand Down Expand Up @@ -568,6 +579,8 @@ public function collect()

$data = [
'nb_statements' => $this->queryCount,
'nb_visible_statements' => count($statements),
'nb_excluded_statements' => $this->queryCount - count($statements),
'nb_failed_statements' => 0,
'accumulated_duration' => $totalTime,
'accumulated_duration_str' => $this->formatDuration($totalTime),
Expand Down Expand Up @@ -599,7 +612,7 @@ public function getWidgets()
"default" => "[]"
],
"queries:badge" => [
"map" => "queries.nb_statements",
"map" => "queries.nb_visible_statements",
"default" => 0
]
];
Expand Down
8 changes: 6 additions & 2 deletions src/LaravelDebugbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,12 @@ function (\Illuminate\Log\Events\MessageLogged $log) use ($logger) {
$queryCollector->setFindSource($dbBacktrace, $middleware);
}

if ($excludePaths = $config->get('debugbar.options.db.backtrace_exclude_paths')) {
$queryCollector->mergeBacktraceExcludePaths($excludePaths);
if ($excludePaths = $config->get('debugbar.options.db.exclude_paths')) {
$queryCollector->mergeExcludePaths($excludePaths);
}

if ($excludeBacktracePaths = $config->get('debugbar.options.db.backtrace_exclude_paths')) {
$queryCollector->mergeBacktraceExcludePaths($excludeBacktracePaths);
}

if ($config->get('debugbar.options.db.explain.enabled')) {
Expand Down
3 changes: 3 additions & 0 deletions src/Resources/queries/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@
}

const $text = $('<span />').text(`${data.nb_statements} statements were executed`);
if (data.nb_excluded_statements) {
$text.append(`, ${data.nb_excluded_statements} have been excluded`);
}
if (data.nb_failed_statements > 0 || this.duplicateQueries.size > 0) {
const details = [];
if (data.nb_failed_statements) {
Expand Down