From 16f876f64713668b246900a2e2ff5c043c32ec65 Mon Sep 17 00:00:00 2001 From: Simon Erkelens Date: Sun, 29 May 2016 14:15:45 +1200 Subject: [PATCH] Show the query number as part of debugging Show the query number, easier to see the amount of queries executed, and for debugging purposes of a certain slow query, also useful, since a breakpoint can be set, with a parameter saying something in the lines of `$this->queryCount == 50`, so the debugger only breaks on that specific query. Without `dev` and `showqueries=1`, performance is not impacted according to XHProf. --- model/connect/Database.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/model/connect/Database.php b/model/connect/Database.php index 5113821ec..5a3832b36 100644 --- a/model/connect/Database.php +++ b/model/connect/Database.php @@ -15,6 +15,13 @@ abstract class SS_Database { * @var DBConnector */ protected $connector = null; + + /** + * Amount of queries executed, for debugging purposes. + * + * @var int + */ + protected $queryCount = 0; /** * Get the current connector @@ -171,6 +178,7 @@ abstract class SS_Database { */ protected function benchmarkQuery($sql, $callback, $parameters = null) { if (isset($_REQUEST['showqueries']) && Director::isDev()) { + $this->queryCount++; $starttime = microtime(true); $result = $callback($sql); $endtime = round(microtime(true) - $starttime, 4); @@ -178,7 +186,7 @@ abstract class SS_Database { if($parameters) { $message .= "\nparams: \"" . implode('", "', $parameters) . '"'; } - Debug::message("\n{$message}\n{$endtime}s\n", false); + Debug::message("\n$this->queryCount: {$message}\n{$endtime}s\n", false); return $result; } else {