@@ -363,6 +363,13 @@ function (\Illuminate\Log\Events\MessageLogged $log) use ($logger) {
363363 $ queryCollector ->setLimits ($ config ->get ('debugbar.options.db.soft_limit ' ), $ config ->get ('debugbar.options.db.hard_limit ' ));
364364 $ queryCollector ->setDurationBackground ($ config ->get ('debugbar.options.db.duration_background ' ));
365365
366+ //allow collecting only queries slower than a specified amount of milliseconds (`slow_threshold`)
367+ $ onlyThreshold = $ config ->get ('debugbar.options.db.only_slow_queries ' , true );
368+ $ threshold = $ config ->get ('debugbar.options.db.slow_threshold ' , false );
369+ if (!$ onlyThreshold && $ threshold ) {
370+ $ queryCollector ->setSlowThreshold ($ threshold );
371+ }
372+
366373 if ($ config ->get ('debugbar.options.db.with_params ' )) {
367374 $ queryCollector ->setRenderSqlWithParams (true );
368375 }
@@ -397,14 +404,12 @@ function (\Illuminate\Log\Events\MessageLogged $log) use ($logger) {
397404
398405 try {
399406 $ events ->listen (
400- function (\Illuminate \Database \Events \QueryExecuted $ query ) {
407+ function (\Illuminate \Database \Events \QueryExecuted $ query ) use ( $ threshold , $ onlyThreshold ) {
401408 if (!app (static ::class)->shouldCollect ('db ' , true )) {
402409 return ; // Issue 776 : We've turned off collecting after the listener was attached
403410 }
404411
405- //allow collecting only queries slower than a specified amount of milliseconds
406- $ threshold = app ('config ' )->get ('debugbar.options.db.slow_threshold ' , false );
407- if (!$ threshold || $ query ->time > $ threshold ) {
412+ if (!$ onlyThreshold || ($ threshold && $ query ->time > $ threshold )) {
408413 $ this ['queries ' ]->addQuery ($ query );
409414 }
410415 }
0 commit comments