Skip to content
Permalink
Browse files

Database: added limit for logged queries into Debugger Bar

  • Loading branch information...
dg committed Dec 13, 2013
1 parent fbb66ed commit 356f1d216f7821401166aa1f19899e5272005d25
Showing with 18 additions and 6 deletions.
  1. +18 −6 Nette/Database/Diagnostics/ConnectionPanel.php
@@ -26,9 +26,15 @@ class ConnectionPanel extends Nette\Object implements Nette\Diagnostics\IBarPane
/** @var int maximum SQL length */
static public $maxLength = 1000;
/** @var int */
public $maxQueries = 100;
/** @var int logged time */
private $totalTime = 0;
/** @var int */
private $count = 0;
/** @var array */
private $queries = array();
@@ -47,6 +53,7 @@ public function logQuery(Nette\Database\Statement $result, array $params = NULL)
if ($this->disabled) {
return;
}
$source = NULL;
foreach (debug_backtrace(FALSE) as $row) {
if (isset($row['file']) && is_file($row['file']) && strpos($row['file'], NETTE_DIR . DIRECTORY_SEPARATOR) !== 0) {
@@ -56,8 +63,12 @@ public function logQuery(Nette\Database\Statement $result, array $params = NULL)
break;
}
}
$this->count++;
$this->totalTime += $result->getTime();
$this->queries[] = array($result->queryString, $params, $result->getTime(), $result->rowCount(), $result->getConnection(), $source);
if ($this->count < $this->maxQueries) {
$this->queries[] = array($result->queryString, $params, $result->getTime(), $result->rowCount(), $result->getConnection(), $source);
}
}
@@ -83,7 +94,7 @@ public function getTab()
{
return '<span title="Nette\\Database ' . htmlSpecialChars($this->name) . '">'
. '<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAEYSURBVBgZBcHPio5hGAfg6/2+R980k6wmJgsJ5U/ZOAqbSc2GnXOwUg7BESgLUeIQ1GSjLFnMwsKGGg1qxJRmPM97/1zXFAAAAEADdlfZzr26miup2svnelq7d2aYgt3rebl585wN6+K3I1/9fJe7O/uIePP2SypJkiRJ0vMhr55FLCA3zgIAOK9uQ4MS361ZOSX+OrTvkgINSjS/HIvhjxNNFGgQsbSmabohKDNoUGLohsls6BaiQIMSs2FYmnXdUsygQYmumy3Nhi6igwalDEOJEjPKP7CA2aFNK8Bkyy3fdNCg7r9/fW3jgpVJbDmy5+PB2IYp4MXFelQ7izPrhkPHB+P5/PjhD5gCgCenx+VR/dODEwD+A3T7nqbxwf1HAAAAAElFTkSuQmCC" />'
. count($this->queries) . ' ' . (count($this->queries) === 1 ? 'query' : 'queries')
. $this->count . ' ' . ($this->count === 1 ? 'query' : 'queries')
. ($this->totalTime ? ' / ' . sprintf('%0.1f', $this->totalTime * 1000) . 'ms' : '')
. '</span>';
}
@@ -139,16 +150,17 @@ public function getPanel()
$s .= '</td><td>' . $rows . '</td></tr>';
}
return empty($this->queries) ? '' :
return $this->count ?
'<style class="nette-debug"> #nette-debug td.nette-DbConnectionPanel-sql { background: white !important }
#nette-debug .nette-DbConnectionPanel-source { color: #BBB !important } </style>
<h1 title="' . htmlSpecialChars($connection->getDsn()) . '">Queries: ' . count($this->queries)
<h1 title="' . htmlSpecialChars($connection->getDsn()) . '">Queries: ' . $this->count
. ($this->totalTime ? ', time: ' . sprintf('%0.3f', $this->totalTime * 1000) . ' ms' : '') . ', ' . htmlSpecialChars($this->name) . '</h1>
<div class="nette-inner nette-DbConnectionPanel">
<table>
<tr><th>Time&nbsp;ms</th><th>SQL Statement</th><th>Params</th><th>Rows</th></tr>' . $s . '
</table>
</div>';
</table>'
. (count($this->queries) < $this->count ? '<p>...and more</p>' : '')
. '</div>' : '';
}
}

0 comments on commit 356f1d2

Please sign in to comment.
You can’t perform that action at this time.