From 9a2a36ce5e322f7ad8ac50b65de54b6a4171da36 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 9 Dec 2004 05:51:20 +0000 Subject: [PATCH] * Defer message cache initialization, shaving a few ms off file cache hits --- includes/Article.php | 5 ----- includes/MessageCache.php | 13 ++++++++++++- includes/Parser.php | 4 +++- includes/Setup.php | 2 +- includes/Skin.php | 3 ++- index.php | 4 ---- languages/Language.php | 14 ++++++++++++++ 7 files changed, 32 insertions(+), 13 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 0ad959cac9..42a368f4d8 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -1956,11 +1956,6 @@ class Article { $called = true; if($this->isFileCacheable()) { $touched = $this->mTouched; - if( $this->mTitle->getPrefixedDBkey() == wfMsg( 'mainpage' ) ) { - # Expire the main page quicker - $expire = wfUnix2Timestamp( time() - 3600 ); - $touched = max( $expire, $touched ); - } $cache = new CacheManager( $this->mTitle ); if($cache->isFileCacheGood( $touched )) { global $wgOut; diff --git a/includes/MessageCache.php b/includes/MessageCache.php index 8d868eccd6..714f462544 100755 --- a/includes/MessageCache.php +++ b/includes/MessageCache.php @@ -23,6 +23,7 @@ class MessageCache var $mMemcKey, $mKeys, $mParserOptions, $mParser; var $mExtensionMessages; var $mInitialised = false; + var $mDeferred = true; function initialise( &$memCached, $useDB, $expiry, $memcPrefix) { $fname = 'MessageCache::initialise'; @@ -44,7 +45,12 @@ class MessageCache $this->mParser = new Parser; wfProfileOut( $fname.'-parser' ); - $this->load(); + # When we first get asked for a message, + # then we'll fill up the cache. If we + # can return a cache hit, this saves + # some extra milliseconds + $this->mDeferred = true; + wfProfileOut( $fname ); } @@ -113,6 +119,7 @@ class MessageCache } } wfProfileOut( $fname ); + $this->mDeferred = false; return $success; } @@ -221,6 +228,10 @@ class MessageCache if( !$this->mInitialised ) { return "<$key>"; } + # If cache initialization was deferred, start it now. + if( $this->mDeferred ) { + $this->load(); + } $message = false; if( !$this->mDisable && $useDB ) { diff --git a/includes/Parser.php b/includes/Parser.php index 0e911d6c92..17c52ad768 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -959,7 +959,9 @@ class Parser wfProfileIn( $fname ); $sk =& $this->mOptions->getSkin(); - $linktrail = wfMsgForContent('linktrail'); + global $wgContLang; + $linktrail = $wgContLang->linkTrail(); + $bits = preg_split( EXT_LINK_BRACKETED, $text, -1, PREG_SPLIT_DELIM_CAPTURE ); $s = $this->replaceFreeExternalLinks( array_shift( $bits ) ); diff --git a/includes/Setup.php b/includes/Setup.php index d609498d03..aa9fa0d867 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -358,7 +358,7 @@ $wgMsgParserOptions = ParserOptions::newFromUser($wgUser); wfSeedRandom(); # Placeholders in case of DB error -$wgTitle = Title::newFromText( wfMsgForContent( 'badtitle' ) ); +$wgTitle = Title::makeTitle( NS_SPECIAL, 'Error' ); $wgArticle = new Article($wgTitle); wfProfileOut( $fname.'-misc2' ); diff --git a/includes/Skin.php b/includes/Skin.php index c114af13cd..4978cdbe38 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -83,7 +83,8 @@ class Skin { /**#@-*/ function Skin() { - $this->linktrail = wfMsgForContent('linktrail'); + global $wgContLang; + $this->linktrail = $wgContLang->linkTrail(); # Cache option lookups done very frequently $options = array( 'highlightbroken', 'hover' ); diff --git a/index.php b/index.php index 1de2977160..5486408c2e 100644 --- a/index.php +++ b/index.php @@ -31,10 +31,6 @@ OutputPage::setEncodings(); # Not really used yet $action = $wgRequest->getVal( "action", "view" ); $title = $wgRequest->getVal( "title" ); -# Placeholders in case of DB error -$wgTitle = Title::newFromText( wfMsgForContent( "badtitle" ) ); -$wgArticle = new Article($wgTitle); - $action = strtolower( trim( $action ) ); if ($wgRequest->getVal( "printable" ) == "yes") { $wgOut->setPrintable(); diff --git a/languages/Language.php b/languages/Language.php index cf4c1ea8ac..87c67c30bf 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -2230,6 +2230,20 @@ class Language { function getExtraHashOptions() { return array(); } + + /** + * A regular expression to match legal word-trailing characters + * which should be merged onto a link of the form [[foo]]bar. + * FIXME + * + * @return string + * @access public + */ + function linkTrail() { + $trail = $this->getMessage( 'linktrail' ); + if( empty( $trail ) ) $trail = Language::linkTrail(); + return $trail; + } } -- 2.20.1