Merge "Avoid DBPerformance warnings in writeToDatabase()"

This commit is contained in:
jenkins-bot 2016-06-10 08:34:56 +00:00 committed by Gerrit Code Review
commit a336d62a35

View file

@ -330,28 +330,30 @@ abstract class MathRenderer {
public function writeToDatabase( $dbw = null ) { public function writeToDatabase( $dbw = null ) {
# Now save it back to the DB: # Now save it back to the DB:
if ( !wfReadOnly() ) { if ( !wfReadOnly() ) {
$dbw = $dbw ?: wfGetDB( DB_MASTER );
LoggerFactory::getInstance( 'Math' )->debug( 'Store entry for $' . $this->tex . LoggerFactory::getInstance( 'Math' )->debug( 'Store entry for $' . $this->tex .
'$ in database (hash:' . $this->getMd5() . ')' ); '$ in database (hash:' . $this->getMd5() . ')' );
$outArray = $this->dbOutArray(); $outArray = $this->dbOutArray();
$method = __METHOD__;
$mathTableName = $this->getMathTableName(); $mathTableName = $this->getMathTableName();
if ( $this->isInDatabase() ) { if ( $this->isInDatabase() ) {
$inputHash = $this->getInputHash(); $inputHash = $this->getInputHash();
$dbw->onTransactionIdle( function () use ( DeferredUpdates::addCallableUpdate( function () use (
$dbw, $outArray, $inputHash, $method, $mathTableName $dbw, $outArray, $inputHash, $mathTableName
) { ) {
$dbw = $dbw ?: wfGetDB( DB_MASTER );
$dbw->update( $mathTableName, $outArray, $dbw->update( $mathTableName, $outArray,
[ 'math_inputhash' => $inputHash ], $method ); [ 'math_inputhash' => $inputHash ], __METHOD__ );
LoggerFactory::getInstance( 'Math' )->debug( LoggerFactory::getInstance( 'Math' )->debug(
'Row updated after db transaction was idle: ' . 'Row updated after db transaction was idle: ' .
var_export( $outArray, true ) . " to database" ); var_export( $outArray, true ) . " to database" );
} ); } );
} else { } else {
$dbw->onTransactionIdle( function () use ( DeferredUpdates::addCallableUpdate( function () use (
$dbw, $outArray, $method, $mathTableName $dbw, $outArray, $mathTableName
) { ) {
$dbw->insert( $mathTableName, $outArray, $method, [ 'IGNORE' ] ); $dbw = $dbw ?: wfGetDB( DB_MASTER );
$dbw->insert( $mathTableName, $outArray, __METHOD__, [ 'IGNORE' ] );
LoggerFactory::getInstance( 'Math' )->debug( LoggerFactory::getInstance( 'Math' )->debug(
'Row inserted after db transaction was idle ' . 'Row inserted after db transaction was idle ' .
var_export( $outArray, true ) . " to database" ); var_export( $outArray, true ) . " to database" );