Make EditPage::getTemplates avoid page table query spam

This changes TemplatesOnThisPageFormatter to use LinkBatch
and LinkBatch/LinkCache to manage the field.

Change-Id: I523158cdffc599d4d29bab91c98e55085130cee2
This commit is contained in:
Aaron Schulz 2019-03-15 02:24:31 -07:00
parent e894410bad
commit 93b24207c1
3 changed files with 21 additions and 10 deletions

View file

@ -66,11 +66,7 @@ class TemplatesOnThisPageFormatter {
} }
# Do a batch existence check # Do a batch existence check
$batch = new LinkBatch; ( new LinkBatch( $templates ) )->execute();
foreach ( $templates as $title ) {
$batch->addObj( $title );
}
$batch->execute();
# Construct the HTML # Construct the HTML
$outText = '<div class="mw-templatesUsedExplanation">'; $outText = '<div class="mw-templatesUsedExplanation">';

View file

@ -3255,8 +3255,9 @@ class Title implements LinkTarget, IDBAccessObject {
} }
if ( $this->mOldRestrictions === false ) { if ( $this->mOldRestrictions === false ) {
$this->mOldRestrictions = $dbr->selectField( 'page', 'page_restrictions', $linkCache = MediaWikiServices::getInstance()->getLinkCache();
[ 'page_id' => $this->getArticleID() ], __METHOD__ ); $linkCache->addLinkObj( $this ); # in case we already had an article ID
$this->mOldRestrictions = $linkCache->getGoodLinkFieldObj( $this, 'restrictions' );
} }
if ( $this->mOldRestrictions != '' ) { if ( $this->mOldRestrictions != '' ) {

View file

@ -141,6 +141,7 @@ class LinkCache {
'revision' => (int)$revision, 'revision' => (int)$revision,
'model' => $model ? (string)$model : null, 'model' => $model ? (string)$model : null,
'lang' => $lang ? (string)$lang : null, 'lang' => $lang ? (string)$lang : null,
'restrictions' => null
] ); ] );
} }
@ -158,8 +159,15 @@ class LinkCache {
'length' => intval( $row->page_len ), 'length' => intval( $row->page_len ),
'redirect' => intval( $row->page_is_redirect ), 'redirect' => intval( $row->page_is_redirect ),
'revision' => intval( $row->page_latest ), 'revision' => intval( $row->page_latest ),
'model' => !empty( $row->page_content_model ) ? strval( $row->page_content_model ) : null, 'model' => !empty( $row->page_content_model )
'lang' => !empty( $row->page_lang ) ? strval( $row->page_lang ) : null, ? strval( $row->page_content_model )
: null,
'lang' => !empty( $row->page_lang )
? strval( $row->page_lang )
: null,
'restrictions' => !empty( $row->page_restrictions )
? strval( $row->page_restrictions )
: null
] ); ] );
} }
@ -198,7 +206,13 @@ class LinkCache {
public static function getSelectFields() { public static function getSelectFields() {
global $wgContentHandlerUseDB, $wgPageLanguageUseDB; global $wgContentHandlerUseDB, $wgPageLanguageUseDB;
$fields = [ 'page_id', 'page_len', 'page_is_redirect', 'page_latest' ]; $fields = [
'page_id',
'page_len',
'page_is_redirect',
'page_latest',
'page_restrictions'
];
if ( $wgContentHandlerUseDB ) { if ( $wgContentHandlerUseDB ) {
$fields[] = 'page_content_model'; $fields[] = 'page_content_model';
} }