From e99e98aa7371bf089dd2af9b33760970236016a3 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Sat, 8 Oct 2016 03:15:15 +0200 Subject: [PATCH] Skin: Reduce database queries for footer links on every page When viewing Special:Blankpage there are still 6 database queries on every page view. 3 of these are from the Skin: > $tpl->set( 'disclaimer', $this->disclaimerLink() ); > $tpl->set( 'privacy', $this->privacyLink() ); > $tpl->set( 'about', $this->aboutLink() ); In Wikimedia production, Xenon flame graphs (reversed) for index.php attribute 22% of LinkCache::fetchPageRow calls to Skin::footerLink(). Add them to Skin::preloadExistence() instead. Change-Id: I61c285be08a2130fb39b75ca717ea83f297c4489 --- includes/skins/Skin.php | 50 ++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/includes/skins/Skin.php b/includes/skins/Skin.php index b60aa10f27..96812ea23f 100644 --- a/includes/skins/Skin.php +++ b/includes/skins/Skin.php @@ -217,6 +217,17 @@ abstract class Skin extends ContextSource { } } + // Footer links (used by SkinTemplate::prepareQuickTemplate) + foreach ( [ + $this->footerLinkTitle( 'privacy', 'privacypage' ), + $this->footerLinkTitle( 'aboutsite', 'aboutpage' ), + $this->footerLinkTitle( 'disclaimers', 'disclaimerpage' ), + ] as $title ) { + if ( $title ) { + $titles[] = $title; + } + } + Hooks::run( 'SkinPreloadExistence', [ &$titles, $this ] ); if ( $titles ) { @@ -921,25 +932,34 @@ abstract class Skin extends ContextSource { * @return string HTML anchor */ public function footerLink( $desc, $page ) { - // if the link description has been set to "-" in the default language, - if ( $this->msg( $desc )->inContentLanguage()->isDisabled() ) { - // then it is disabled, for all languages. + $title = $this->footerLinkTitle( $desc, $page ); + if ( !$title ) { return ''; - } else { - // Otherwise, we display the link for the user, described in their - // language (which may or may not be the same as the default language), - // but we make the link target be the one site-wide page. - $title = Title::newFromText( $this->msg( $page )->inContentLanguage()->text() ); + } - if ( !$title ) { - return ''; - } + return Linker::linkKnown( + $title, + $this->msg( $desc )->escaped() + ); + } - return Linker::linkKnown( - $title, - $this->msg( $desc )->escaped() - ); + /** + * @param string $desc + * @param string $page + * @return Title|null + */ + private function footerLinkTitle( $desc, $page ) { + // If the link description has been set to "-" in the default language, + if ( $this->msg( $desc )->inContentLanguage()->isDisabled() ) { + // then it is disabled, for all languages. + return null; } + // Otherwise, we display the link for the user, described in their + // language (which may or may not be the same as the default language), + // but we make the link target be the one site-wide page. + $title = Title::newFromText( $this->msg( $page )->inContentLanguage()->text() ); + + return $title ?: null; } /** -- 2.20.1