Merge pull request #5606 from Firesphere/patch-1

Show the query number as part of debugging
This commit is contained in:
Damian Mooyman 2016-06-28 17:59:10 +12:00 committed by GitHub
commit 803cef4f3c

View File

@ -16,6 +16,13 @@ abstract class SS_Database {
*/ */
protected $connector = null; protected $connector = null;
/**
* Amount of queries executed, for debugging purposes.
*
* @var int
*/
protected $queryCount = 0;
/** /**
* Get the current connector * Get the current connector
* *
@ -171,6 +178,7 @@ abstract class SS_Database {
*/ */
protected function benchmarkQuery($sql, $callback, $parameters = null) { protected function benchmarkQuery($sql, $callback, $parameters = null) {
if (isset($_REQUEST['showqueries']) && Director::isDev()) { if (isset($_REQUEST['showqueries']) && Director::isDev()) {
$this->queryCount++;
$starttime = microtime(true); $starttime = microtime(true);
$result = $callback($sql); $result = $callback($sql);
$endtime = round(microtime(true) - $starttime, 4); $endtime = round(microtime(true) - $starttime, 4);
@ -178,7 +186,7 @@ abstract class SS_Database {
if($parameters) { if($parameters) {
$message .= "\nparams: \"" . implode('", "', $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; return $result;
} else { } else {