From 93b24207c1cb8dac1ff4c810da2ede7ccba987f0 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Fri, 15 Mar 2019 02:24:31 -0700 Subject: [PATCH] Make EditPage::getTemplates avoid page table query spam This changes TemplatesOnThisPageFormatter to use LinkBatch and LinkBatch/LinkCache to manage the field. Change-Id: I523158cdffc599d4d29bab91c98e55085130cee2 --- includes/TemplatesOnThisPageFormatter.php | 6 +----- includes/Title.php | 5 +++-- includes/cache/LinkCache.php | 20 +++++++++++++++++--- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/includes/TemplatesOnThisPageFormatter.php b/includes/TemplatesOnThisPageFormatter.php index 494c7bfc86..bca1ef651a 100644 --- a/includes/TemplatesOnThisPageFormatter.php +++ b/includes/TemplatesOnThisPageFormatter.php @@ -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 = '
'; diff --git a/includes/Title.php b/includes/Title.php index cf76c0d37b..88a7efb8df 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -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 != '' ) { diff --git a/includes/cache/LinkCache.php b/includes/cache/LinkCache.php index b3dc00468b..fb416f040a 100644 --- a/includes/cache/LinkCache.php +++ b/includes/cache/LinkCache.php @@ -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'; } -- 2.20.1