Avoid DBPerformance warnings in writeToDatabase()

Switch to using DeferredUpdates.

Bug: T92357
Change-Id: I64179317ab8ed21c864a4cb237cd4ed8705393e1
This commit is contained in:
Aaron Schulz 2016-06-02 21:58:44 -07:00
parent fcbf2ba093
commit 9a1dede261
1 changed files with 10 additions and 8 deletions

View File

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