Merge "Improve debugging"

This commit is contained in:
jenkins-bot 2021-02-05 21:32:56 +00:00 committed by Gerrit Code Review
commit 33dee20ee1
2 changed files with 64 additions and 41 deletions

View file

@ -287,7 +287,6 @@ class MathMathML extends MathRenderer {
* Calculates the HTTP POST Data for the request. Depends on the settings
* and the input string only.
* @return string HTTP POST data
* @throws MWException
*/
public function getPostData() {
$input = $this->getTex();
@ -297,7 +296,14 @@ class MathMathML extends MathRenderer {
} elseif ( $this->inputType == 'ascii' ) {
$out = 'type=asciimath&q=' . rawurlencode( $input );
} else {
throw new MWException( 'Internal error: Restbase should be used for tex rendering' );
if ( $this->getMathStyle() === 'inlineDisplaystyle' ) {
// default preserve the (broken) layout as it was
$out = 'type=inline-TeX&q=' . rawurlencode( '{\\displaystyle ' . $input . '}' );
} elseif ( $this->getMathStyle() === 'inline' ) {
$out = 'type=inline-TeX&q=' . rawurlencode( $input );
} else {
$out = 'type=tex&q=' . rawurlencode( $input );
}
}
$this->logger->debug( 'Get post data: ' . $out );
return $out;
@ -540,6 +546,7 @@ class MathMathML extends MathRenderer {
if ( $this->getMathTableName() == 'mathoid' ) {
$out['math_input'] = $out['math_inputtex'];
unset( $out['math_inputtex'] );
$out['math_png'] = $this->png;
}
return $out;
}

View file

@ -188,8 +188,13 @@ abstract class MathRenderer {
$renderer = new MathMathML( $tex, $params );
}
}
LoggerFactory::getInstance( 'Math' )->debug( 'Start rendering $' . $renderer->tex .
'$ in mode ' . $mode );
LoggerFactory::getInstance( 'Math' )->debug(
'Start rendering "{tex}" in mode {mode}',
[
'tex' => $tex,
'mode' => $mode
]
);
return $renderer;
}
@ -339,42 +344,47 @@ abstract class MathRenderer {
*/
public function writeToDatabase( $dbw = null ) {
# Now save it back to the DB:
if ( !wfReadOnly() ) {
$this->logger->debug( 'Store entry for $' . $this->tex .
'$ in database (hash:' . $this->getMd5() . ')' );
$outArray = $this->dbOutArray();
$mathTableName = $this->getMathTableName();
$fname = __METHOD__;
if ( $this->isInDatabase() ) {
$inputHash = $this->getInputHash();
DeferredUpdates::addCallableUpdate( function () use (
$dbw, $outArray, $inputHash, $mathTableName, $fname
) {
$dbw = $dbw ?: wfGetDB( DB_MASTER );
if ( wfReadOnly() ) {
return;
}
$outArray = $this->dbOutArray();
$mathTableName = $this->getMathTableName();
$fname = __METHOD__;
if ( $this->isInDatabase() ) {
$this->debug( 'Update database entry' );
$inputHash = $this->getInputHash();
DeferredUpdates::addCallableUpdate( function () use (
$dbw, $outArray, $inputHash, $mathTableName, $fname
) {
$dbw = $dbw ?: wfGetDB( DB_MASTER );
$dbw->update( $mathTableName, $outArray,
[ 'math_inputhash' => $inputHash ], $fname );
$this->logger->debug(
'Row updated after db transaction was idle: ' .
var_export( $outArray, true ) . " to database" );
} );
} else {
DeferredUpdates::addCallableUpdate( function () use (
$dbw, $outArray, $mathTableName, $fname
) {
$dbw = $dbw ?: wfGetDB( DB_MASTER );
$dbw->update( $mathTableName, $outArray,
[ 'math_inputhash' => $inputHash ], $fname );
$this->logger->debug(
'Row updated after db transaction was idle: ' .
var_export( $outArray, true ) . " to database" );
} );
} else {
$this->storedInDatabase = true;
$this->debug( 'Store new entry in database' );
DeferredUpdates::addCallableUpdate( function () use (
$dbw, $outArray, $mathTableName, $fname
) {
$dbw = $dbw ?: wfGetDB( DB_MASTER );
$dbw->insert( $mathTableName, $outArray, $fname, [ 'IGNORE' ] );
$this->logger->debug(
'Row inserted after db transaction was idle ' .
var_export( $outArray, true ) . " to database" );
if ( $dbw->affectedRows() == 0 ) {
// That's the price for the delayed update.
$this->logger->warning(
'Entry could not be written. Might be changed in between.' );
}
} );
}
$dbw->insert( $mathTableName, $outArray, $fname, [ 'IGNORE' ] );
LoggerFactory::getInstance( 'Math' )->debug(
'Row inserted after db transaction was idle {out}.',
[
'out' => var_export( $outArray, true ),
]
);
if ( $dbw->affectedRows() == 0 ) {
// That's the price for the delayed update.
$this->logger->warning(
'Entry could not be written. Might be changed in between.' );
}
} );
}
}
@ -444,13 +454,13 @@ abstract class MathRenderer {
* @return bool
*/
public function writeCache() {
$this->logger->debug( 'Writing of cache requested.' );
$this->debug( 'Writing of cache requested' );
if ( $this->isChanged() ) {
$this->logger->debug( 'Change detected. Perform writing.' );
$this->debug( 'Change detected. Perform writing' );
$this->writeToDatabase();
return true;
} else {
$this->logger->debug( "Nothing was changed. Don't write to database." );
$this->debug( "Nothing was changed. Don't write to database" );
return false;
}
}
@ -618,14 +628,17 @@ abstract class MathRenderer {
public function checkTeX() {
if ( $this->texSecure || self::getDisableTexFilter() == 'always' ) {
// equation was already checked or checking is disabled
$this->debug( 'Skip TeX check ' );
return true;
} else {
if ( self::getDisableTexFilter() == 'new' && $this->mode != 'source' ) {
if ( $this->readFromDatabase() ) {
$this->debug( 'Skip TeX check' );
$this->texSecure = true;
return true;
}
}
$this->debug( 'Perform TeX check' );
return $this->doCheck();
}
}
@ -743,4 +756,7 @@ abstract class MathRenderer {
return $this->png;
}
protected function debug( $msg ) {
$this->logger->debug( "$msg for \"{tex}\".", [ 'tex' => $this->userInputTex ] );
}
}