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:
parent
e894410bad
commit
93b24207c1
3 changed files with 21 additions and 10 deletions
|
|
@ -66,11 +66,7 @@ class TemplatesOnThisPageFormatter {
|
|||
}
|
||||
|
||||
# Do a batch existence check
|
||||
$batch = new LinkBatch;
|
||||
foreach ( $templates as $title ) {
|
||||
$batch->addObj( $title );
|
||||
}
|
||||
$batch->execute();
|
||||
( new LinkBatch( $templates ) )->execute();
|
||||
|
||||
# Construct the HTML
|
||||
$outText = '<div class="mw-templatesUsedExplanation">';
|
||||
|
|
|
|||
|
|
@ -3255,8 +3255,9 @@ class Title implements LinkTarget, IDBAccessObject {
|
|||
}
|
||||
|
||||
if ( $this->mOldRestrictions === false ) {
|
||||
$this->mOldRestrictions = $dbr->selectField( 'page', 'page_restrictions',
|
||||
[ 'page_id' => $this->getArticleID() ], __METHOD__ );
|
||||
$linkCache = MediaWikiServices::getInstance()->getLinkCache();
|
||||
$linkCache->addLinkObj( $this ); # in case we already had an article ID
|
||||
$this->mOldRestrictions = $linkCache->getGoodLinkFieldObj( $this, 'restrictions' );
|
||||
}
|
||||
|
||||
if ( $this->mOldRestrictions != '' ) {
|
||||
|
|
|
|||
20
includes/cache/LinkCache.php
vendored
20
includes/cache/LinkCache.php
vendored
|
|
@ -141,6 +141,7 @@ class LinkCache {
|
|||
'revision' => (int)$revision,
|
||||
'model' => $model ? (string)$model : null,
|
||||
'lang' => $lang ? (string)$lang : null,
|
||||
'restrictions' => null
|
||||
] );
|
||||
}
|
||||
|
||||
|
|
@ -158,8 +159,15 @@ class LinkCache {
|
|||
'length' => intval( $row->page_len ),
|
||||
'redirect' => intval( $row->page_is_redirect ),
|
||||
'revision' => intval( $row->page_latest ),
|
||||
'model' => !empty( $row->page_content_model ) ? strval( $row->page_content_model ) : null,
|
||||
'lang' => !empty( $row->page_lang ) ? strval( $row->page_lang ) : null,
|
||||
'model' => !empty( $row->page_content_model )
|
||||
? 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() {
|
||||
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 ) {
|
||||
$fields[] = 'page_content_model';
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue