RevisionRenderer should set revision ID/Timestamp in ParserOutput

ParserOutput object wraps revision ID and revision timestamp
of the parsed revision. Currently ParserCache sets these properties,
but it's not at all it's job - whatever generates the ParserOutput
knows much better what revision it parsed. This also allows us to
simplify ParserCache and easier switch it to PageRecord.

I've only removed setting the timestamp inside ParserCache
cause it's a blocker for page record, I will do followupus
to remove the $revId parameter from ParserCache as well.

cacheRevisionId should also be renamed, but later.

Bug: T278284
Change-Id: I9a82e9fd154b29a81d1f7a3c4abb073c9a27314e
This commit is contained in:
Petr Pchelko 2021-03-24 07:19:38 -06:00
parent 526e8f0ee9
commit 37030c04f0
3 changed files with 11 additions and 5 deletions

View file

@ -259,12 +259,16 @@ class RenderedRevision implements SlotRenderingProvider {
* @return ParserOutput
*/
private function getSlotParserOutputUncached( Content $content, $withHtml ) {
return $content->getParserOutput(
$parserOutput = $content->getParserOutput(
$this->title,
$this->revision->getId(),
$this->options,
$withHtml
);
// Save the rev_id and timestamp so that we don't have to load the revision row on view
$parserOutput->setCacheRevisionId( $this->revision->getId() );
$parserOutput->setTimestamp( $this->revision->getTimestamp() );
return $parserOutput;
}
/**

View file

@ -497,9 +497,6 @@ class ParserCache {
$metadata->getUsedOptions()
);
// Save the timestamp so that we don't have to load the revision row on view
$parserOutput->setTimestamp( $wikiPage->getTimestamp() );
$msg = "Saved in parser cache with key $parserOutputKey" .
" and timestamp $cacheTime" .
" and revision id $revId.";

View file

@ -385,7 +385,12 @@ class RevisionRendererTest extends MediaWikiIntegrationTestCase {
$this->assertSame( $rev, $rr->getRevision() );
$this->assertSame( $options, $rr->getOptions() );
$html = $rr->getRevisionParserOutput()->getText();
$parserOutput = $rr->getRevisionParserOutput();
// Assert parser output recorded timestamp and parsed rev_id
$this->assertSame( $rev->getId(), $parserOutput->getCacheRevisionId() );
$this->assertSame( $rev->getTimestamp(), $parserOutput->getTimestamp() );
$html = $parserOutput->getText();
// Suppressed content should be visible in raw mode
$this->assertStringContainsString( 'page:' . __CLASS__, $html );