Skip to content

Commit

Permalink
Reset query timing metrics for begin/commit/insert multi calls.
Browse files Browse the repository at this point in the history
Apply patch from @mensler to reset the query metrics for transaction
operations, and for each iteration of an insertMulti call. This helps
provide more accurate query times.

Refs #9014
  • Loading branch information
markstory committed Jun 23, 2016
1 parent 7735a61 commit 92a50d0
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/Cake/Model/Datasource/DboSource.php
Expand Up @@ -2302,6 +2302,7 @@ public function begin() {

$this->_transactionNesting = 0;
if ($this->fullDebug) {
$this->took = $this->numRows = $this->affected = false;
$this->logQuery('BEGIN');
}
return $this->_transactionStarted = $this->_connection->beginTransaction();
Expand All @@ -2315,6 +2316,7 @@ public function begin() {
protected function _beginNested() {
$query = 'SAVEPOINT LEVEL' . ++$this->_transactionNesting;
if ($this->fullDebug) {
$this->took = $this->numRows = $this->affected = false;
$this->logQuery($query);
}
$this->_connection->exec($query);
Expand All @@ -2335,6 +2337,7 @@ public function commit() {

if ($this->_transactionNesting === 0) {
if ($this->fullDebug) {
$this->took = $this->numRows = $this->affected = false;
$this->logQuery('COMMIT');
}
$this->_transactionStarted = false;
Expand All @@ -2357,6 +2360,7 @@ public function commit() {
protected function _commitNested() {
$query = 'RELEASE SAVEPOINT LEVEL' . $this->_transactionNesting--;
if ($this->fullDebug) {
$this->took = $this->numRows = $this->affected = false;
$this->logQuery($query);
}
$this->_connection->exec($query);
Expand All @@ -2377,6 +2381,7 @@ public function rollback() {

if ($this->_transactionNesting === 0) {
if ($this->fullDebug) {
$this->took = $this->numRows = $this->affected = false;
$this->logQuery('ROLLBACK');
}
$this->_transactionStarted = false;
Expand All @@ -2399,6 +2404,7 @@ public function rollback() {
protected function _rollbackNested() {
$query = 'ROLLBACK TO SAVEPOINT LEVEL' . $this->_transactionNesting--;
if ($this->fullDebug) {
$this->took = $this->numRows = $this->affected = false;
$this->logQuery($query);
}
$this->_connection->exec($query);
Expand Down Expand Up @@ -3190,10 +3196,13 @@ public function insertMulti($table, $fields, $values) {
$statement->bindValue($i, $val, $columnMap[$col]);
$i += 1;
}
$t = microtime(true);
$statement->execute();
$statement->closeCursor();

if ($this->fullDebug) {
$this->took = round((microtime(true) - $t) * 1000, 0);
$this->numRows = $this->affected = $statement->rowCount();
$this->logQuery($sql, $value);
}
}
Expand Down

0 comments on commit 92a50d0

Please sign in to comment.