Skip to content
Permalink
Browse files

Reset query timing metrics for begin/commit/insert multi calls.

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 92a50d05dcd820434e0799d9c22beb823a590bf1
Showing with 9 additions and 0 deletions.
  1. +9 −0 lib/Cake/Model/Datasource/DboSource.php
@@ -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();
@@ -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);
@@ -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;
@@ -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);
@@ -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;
@@ -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);
@@ -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);
}
}

0 comments on commit 92a50d0

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