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.
This commit is contained in:
Simon Erkelens 2016-05-29 14:15:45 +12:00
parent f4037fe319
commit 16f876f647

View File

@ -16,6 +16,13 @@ abstract class SS_Database {
*/
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 {