Bypass warming red link cache for wikitext requests

Wikitext editor doesn't need to know about redlinks
on the page, so this is a waste of time. If the user
switches to VE, they will do a fresh metadata request
at that point.

Change-Id: I57f3fe3fca47dde03bba7905f763abc8a43d0653
This commit is contained in:
Ed Sanders 2017-01-12 16:33:49 -08:00
parent a4543a7336
commit 3577035825

View file

@ -445,34 +445,39 @@ class ApiVisualEditor extends ApiBase {
// We do the lookup for the current version. This might not be entirely complete // We do the lookup for the current version. This might not be entirely complete
// if we're loading an oldid, but it'll probably be close enough, and LinkCache // if we're loading an oldid, but it'll probably be close enough, and LinkCache
// will automatically request any additional data it needs. // will automatically request any additional data it needs.
$links = []; // We only do this for visual edits, as the wikitext editor doesn't need to know
$wikipage = WikiPage::factory( $title ); // about redlinks on the page. If the user switches to VE, they will do a fresh
$popts = $wikipage->makeParserOptions( 'canonical' ); // metadata request at that point.
$cached = ParserCache::singleton()->get( $article, $popts, true ); $links = null;
$links = [ if ( $params['paction'] !== 'wikitext' ) {
// Array of linked pages that are missing $wikipage = WikiPage::factory( $title );
'missing' => [], $popts = $wikipage->makeParserOptions( 'canonical' );
// For current revisions: 1 (treat all non-missing pages as known) $cached = ParserCache::singleton()->get( $article, $popts, true );
// For old revisions: array of linked pages that are known $links = [
'known' => $restoring || !$cached ? [] : 1, // Array of linked pages that are missing
]; 'missing' => [],
if ( $cached ) { // For current revisions: 1 (treat all non-missing pages as known)
foreach ( $cached->getLinks() as $namespace => $cachedTitles ) { // For old revisions: array of linked pages that are known
foreach ( $cachedTitles as $cachedTitleText => $exists ) { 'known' => $restoring || !$cached ? [] : 1,
$cachedTitle = Title::makeTitle( $namespace, $cachedTitleText ); ];
if ( !$cachedTitle->isKnown() ) { if ( $cached ) {
$links['missing'][] = $cachedTitle->getPrefixedText(); foreach ( $cached->getLinks() as $namespace => $cachedTitles ) {
} elseif ( $links['known'] !== 1 ) { foreach ( $cachedTitles as $cachedTitleText => $exists ) {
$links['known'][] = $cachedTitle->getPrefixedText(); $cachedTitle = Title::makeTitle( $namespace, $cachedTitleText );
if ( !$cachedTitle->isKnown() ) {
$links['missing'][] = $cachedTitle->getPrefixedText();
} elseif ( $links['known'] !== 1 ) {
$links['known'][] = $cachedTitle->getPrefixedText();
}
} }
} }
} }
} // Add information about current page
// Add information about current page if ( !$title->isKnown() ) {
if ( !$title->isKnown() ) { $links['missing'][] = $title->getPrefixedText();
$links['missing'][] = $title->getPrefixedText(); } elseif ( $links['known'] !== 1 ) {
} elseif ( $links['known'] !== 1 ) { $links['known'][] = $title->getPrefixedText();
$links['known'][] = $title->getPrefixedText(); }
} }
// On parser cache miss, just don't bother populating red link data // On parser cache miss, just don't bother populating red link data