Force a reparse if output from cache is not Parsoid's default

Avoids any issue with not respecting the explicit version in accept
headers.  However, it will effectively mean a cache miss on every
request after a Parsoid version bump.

Bug: T333606
Change-Id: Ia70f819df79fbb12a5b1dd6a98bfe0b968808d18
This commit is contained in:
Arlo Breault 2023-05-29 15:18:38 -04:00
parent 5067c5453e
commit ca6e56823e
2 changed files with 58 additions and 2 deletions

View file

@ -744,6 +744,26 @@ class HtmlOutputRendererHelper implements HtmlOutputHelper {
$this->revisionOrId,
$flags
);
// T333606: Force a reparse if the version coming from cache is not the default
if ( $status->isOK() ) {
$parserOutput = $status->getValue();
$pageBundleData = $parserOutput->getExtensionData(
PageBundleParserOutputConverter::PARSOID_PAGE_BUNDLE_KEY
);
$cachedVersion = $pageBundleData['version'] ?? null;
if (
$cachedVersion !== null && // T325137: BadContentModel, no sense in reparsing
$cachedVersion !== Parsoid::defaultHTMLVersion()
) {
$status = $this->parsoidOutputAccess->getParserOutput(
$this->page,
$parserOptions,
$this->revisionOrId,
$flags | ParsoidOutputAccess::OPT_FORCE_PARSE
);
}
}
} else {
$status = $this->parsoidOutputAccess->parse(
$this->page,

View file

@ -162,6 +162,7 @@ class HtmlOutputRendererHelperTest extends MediaWikiIntegrationTestCase {
* @param string $html
* @param RevisionRecord|int|null $rev
* @param PageIdentity $page
* @param string $version
*
* @return ParserOutput
*/
@ -169,7 +170,8 @@ class HtmlOutputRendererHelperTest extends MediaWikiIntegrationTestCase {
ParserOptions $parserOpts,
string $html,
$rev,
PageIdentity $page
PageIdentity $page,
string $version = '08-15'
): ParserOutput {
$lang = $parserOpts->getTargetLanguage();
$lang = $lang ? $lang->getCode() : 'en';
@ -188,7 +190,7 @@ class HtmlOutputRendererHelperTest extends MediaWikiIntegrationTestCase {
't3s7' => [ 'dsr' => [ 0, 0, 0, 0 ] ],
] ],
'mw' => [ 'ids' => [] ],
'version' => '08-15',
'version' => $version,
'headers' => [
'content-language' => $lang
]
@ -1079,4 +1081,38 @@ class HtmlOutputRendererHelperTest extends MediaWikiIntegrationTestCase {
$this->assertSame( '0/dummy-output', $output->getExtensionData( 'parsoid-render-id' ) );
}
/**
* HtmlOutputRendererHelper should force a reparse if getParserOuput doesn't
* return Parsoid's default version.
*/
public function testForceDefault() {
$page = $this->getExistingTestPage();
$poa = $this->createMock( ParsoidOutputAccess::class );
$poa->method( 'getParserOutput' )
->willReturnCallback( function (
PageIdentity $page,
ParserOptions $parserOpts,
$revision = null,
int $options = 0
) {
static $first = true;
if ( $first ) {
$version = '1.1.1'; // Not the default
$first = false;
} else {
$version = Parsoid::defaultHTMLVersion();
$this->assertGreaterThan( 0, $options & ParsoidOutputAccess::OPT_FORCE_PARSE );
}
$html = $this->getMockHtml( $revision );
$pout = $this->makeParserOutput( $parserOpts, $html, $revision, $page, $version );
return Status::newGood( $pout );
} );
$helper = $this->newHelper( null, $poa );
$helper->init( $page, [], $this->newUser() );
$pb = $helper->getPageBundle();
$this->assertSame( $pb->version, Parsoid::defaultHTMLVersion() );
}
}