diff --git a/composer.json b/composer.json
index 93fbb9a8c..622cea34b 100644
--- a/composer.json
+++ b/composer.json
@@ -18,7 +18,7 @@
],
"require": {
"php": "^8.1",
- "php-debugbar/php-debugbar": "~2.2.0",
+ "php-debugbar/php-debugbar": "^2.2.4",
"illuminate/routing": "^9|^10|^11|^12",
"illuminate/session": "^9|^10|^11|^12",
"illuminate/support": "^9|^10|^11|^12",
diff --git a/config/debugbar.php b/config/debugbar.php
index 8ee60a600..2d86208c3 100644
--- a/config/debugbar.php
+++ b/config/debugbar.php
@@ -232,7 +232,8 @@
],
'hints' => env('DEBUGBAR_OPTIONS_DB_HINTS', false), // Show hints for common mistakes
'show_copy' => env('DEBUGBAR_OPTIONS_DB_SHOW_COPY', true), // Show copy button next to the query,
- 'slow_threshold' => env('DEBUGBAR_OPTIONS_DB_SLOW_THRESHOLD', false), // Only track queries that last longer than this time in ms
+ 'only_slow_queries' => env('DEBUGBAR_OPTIONS_DB_ONLY_SLOW_QUERIES', true), // Only track queries that last longer than `slow_threshold`
+ 'slow_threshold' => env('DEBUGBAR_OPTIONS_DB_SLOW_THRESHOLD', false), // Max query execution time (ms). Exceeding queries will be highlighted
'memory_usage' => env('DEBUGBAR_OPTIONS_DB_MEMORY_USAGE', false), // Show queries memory usage
'soft_limit' => (int) env('DEBUGBAR_OPTIONS_DB_SOFT_LIMIT', 100), // After the soft limit, no parameters/backtrace are captured
'hard_limit' => (int) env('DEBUGBAR_OPTIONS_DB_HARD_LIMIT', 500), // After the hard limit, queries are ignored
diff --git a/src/DataCollector/QueryCollector.php b/src/DataCollector/QueryCollector.php
index d9e491d8b..b6922276f 100644
--- a/src/DataCollector/QueryCollector.php
+++ b/src/DataCollector/QueryCollector.php
@@ -517,6 +517,7 @@ public function collect()
'start' => $query['start'] ?? null,
'duration' => $query['time'],
'duration_str' => ($query['type'] == 'transaction') ? '' : $this->formatDuration($query['time']),
+ 'slow' => $this->slowThreshold && $this->slowThreshold <= $query['time'],
'memory' => $query['memory'],
'memory_str' => $query['memory'] ? $this->getDataFormatter()->formatBytes($query['memory']) : null,
'filename' => $this->getDataFormatter()->formatSource($source, true),
diff --git a/src/LaravelDebugbar.php b/src/LaravelDebugbar.php
index d3a3d85df..6ef7d8eae 100644
--- a/src/LaravelDebugbar.php
+++ b/src/LaravelDebugbar.php
@@ -363,6 +363,11 @@ function (\Illuminate\Log\Events\MessageLogged $log) use ($logger) {
$queryCollector->setLimits($config->get('debugbar.options.db.soft_limit'), $config->get('debugbar.options.db.hard_limit'));
$queryCollector->setDurationBackground($config->get('debugbar.options.db.duration_background'));
+ $threshold = $config->get('debugbar.options.db.slow_threshold', false);
+ if ($threshold && !$config->get('debugbar.options.db.only_slow_queries', true)) {
+ $queryCollector->setSlowThreshold($threshold);
+ }
+
if ($config->get('debugbar.options.db.with_params')) {
$queryCollector->setRenderSqlWithParams(true);
}
@@ -402,9 +407,10 @@ function (\Illuminate\Database\Events\QueryExecuted $query) {
return; // Issue 776 : We've turned off collecting after the listener was attached
}
- //allow collecting only queries slower than a specified amount of milliseconds
$threshold = app('config')->get('debugbar.options.db.slow_threshold', false);
- if (!$threshold || $query->time > $threshold) {
+ $onlyThreshold = app('config')->get('debugbar.options.db.only_slow_queries', true);
+ //allow collecting only queries slower than a specified amount of milliseconds
+ if (!$onlyThreshold || !$threshold || $query->time > $threshold) {
$this['queries']->addQuery($query);
}
}
diff --git a/src/Resources/queries/widget.js b/src/Resources/queries/widget.js
index eea29e21f..b9de555a2 100644
--- a/src/Resources/queries/widget.js
+++ b/src/Resources/queries/widget.js
@@ -231,6 +231,9 @@
.attr('data-duplicate', false)
.append($('').addClass(csscls('sql name')).text(statement.sql));
} else {
+ if (statement.slow) {
+ $li.addClass(csscls('sql-slow'));
+ }
const $code = $('').html(PhpDebugBar.Widgets.highlight(statement.sql, 'sql')).addClass(csscls('sql')),
duplicated = this.duplicateQueries.has(statement);
$li.attr('data-connection', statement.connection)