From: Timo Tijhof Date: Sat, 8 Oct 2016 01:15:15 +0000 (+0200) Subject: Skin: Reduce database queries for footer links on every page X-Git-Tag: 1.31.0-rc.0~4836^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_aide%28?a=commitdiff_plain;h=e99e98aa7371bf089dd2af9b33760970236016a3;p=lhc%2Fweb%2Fwiklou.git 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 --- 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; } /**