mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
f4037fe319
commit
16f876f647
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user