From 27a86e8860fce18b02ef52084d6aa8d0055708b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armando=20L=C3=BCscher?= Date: Wed, 23 Jun 2021 10:56:20 +0000 Subject: [PATCH 1/3] Add slashes to relation strings in console output --- src/Outputs/Console.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Outputs/Console.php b/src/Outputs/Console.php index 6b4680f..7a90366 100644 --- a/src/Outputs/Console.php +++ b/src/Outputs/Console.php @@ -42,10 +42,10 @@ protected function getOutputContent(Collection $detectedQueries) $output .= "console.warn('Found the following N+1 queries in this request:\\n\\n"; foreach ($detectedQueries as $detectedQuery) { $output .= "Model: ".addslashes($detectedQuery['model'])." => Relation: ".addslashes($detectedQuery['relation']); - $output .= " - You should add \"with(\'".$detectedQuery['relation']."\')\" to eager-load this relation."; + $output .= " - You should add \"with(\'".addslashes($detectedQuery['relation'])."\')\" to eager-load this relation."; $output .= "\\n\\n"; $output .= "Model: ".addslashes($detectedQuery['model'])."\\n"; - $output .= "Relation: ".$detectedQuery['relation']."\\n"; + $output .= "Relation: ".addslashes($detectedQuery['relation'])."\\n"; $output .= "Num-Called: ".$detectedQuery['count']."\\n"; $output .= "\\n"; $output .= 'Call-Stack:\\n'; From 51aca02bc82d1a26457e08f693ef0ad7def2b4f1 Mon Sep 17 00:00:00 2001 From: Scott Zirkel Date: Wed, 21 Sep 2022 11:09:45 -0500 Subject: [PATCH 2/3] Update QueryDetector.php Return if no sources are found. --- src/QueryDetector.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/QueryDetector.php b/src/QueryDetector.php index 0d3dcc6..8deb29a 100755 --- a/src/QueryDetector.php +++ b/src/QueryDetector.php @@ -74,6 +74,10 @@ public function logQuery($query, Collection $backtrace) } $sources = $this->findSource($backtrace); + + if (empty($sources)) { + return; + } $key = md5($query->sql . $model . $relationName . $sources[0]->name . $sources[0]->line); From d12d3b05dd9adec949603d05084ce6cd73e1fb5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Vdovec?= Date: Tue, 11 Oct 2022 10:46:52 +0200 Subject: [PATCH 3/3] Fix typo - then -> than --- config/config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.php b/config/config.php index 03f5ec7..84f1765 100644 --- a/config/config.php +++ b/config/config.php @@ -9,7 +9,7 @@ /* * Threshold level for the N+1 query detection. If a relation query will be - * executed more then this amount, the detector will notify you about it. + * executed more than this amount, the detector will notify you about it. */ 'threshold' => (int) env('QUERY_DETECTOR_THRESHOLD', 1),