From: Tim Starling Date: Wed, 20 Apr 2005 15:42:08 +0000 (+0000) Subject: Setup.php-DateFormatter was using a lot of CPU time on the live site. Moved it to... X-Git-Tag: 1.5.0alpha1~228 X-Git-Url: http://git.cyclocoop.org/fichier?a=commitdiff_plain;h=66507cbde34ea2b5ca6ff83198f1568b76bb60af;p=lhc%2Fweb%2Fwiklou.git Setup.php-DateFormatter was using a lot of CPU time on the live site. Moved it to on-demand initialisation, with memcached assistance. --- diff --git a/includes/DateFormatter.php b/includes/DateFormatter.php index 4682f394ad..f135d32617 100755 --- a/includes/DateFormatter.php +++ b/includes/DateFormatter.php @@ -111,6 +111,22 @@ class DateFormatter $this->rules[DF_NONE][DF_ISO2] = DF_ISO1; } + /** + * @static + */ + function &getInstance() { + global $wgDBname, $wgMemc; + static $dateFormatter = false; + if ( !$dateFormatter ) { + $dateFormatter = $wgMemc->get( "$wgDBname:dateformatter" ); + if ( !$dateFormatter ) { + $dateFormatter = new DateFormatter; + $wgMemc->set( "$wgDBname:dateformatter", $dateFormatter, 3600 ); + } + } + return $dateFormatter; + } + /** * @param $preference * @param $text @@ -279,7 +295,8 @@ class DateFormatter * @todo document */ function wfMainDateReplace( $matches ) { - global $wgDateFormatter; - return $wgDateFormatter->replace( $matches ); + $df =& DateFormatter::getInstance(); + return $df->replace( $matches ); } + ?> diff --git a/includes/Parser.php b/includes/Parser.php index 456e3af09c..9ad6ed8e25 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -76,7 +76,7 @@ define( 'EXT_IMAGE_REGEX', * performs brace substitution on MediaWiki messages * * Globals used: - * objects: $wgLang, $wgDateFormatter, $wgLinkCache + * objects: $wgLang, $wgLinkCache * * NOT $wgArticle, $wgUser or $wgTitle. Keep them away! * @@ -651,8 +651,8 @@ class Parser $text = $this->doHeadings( $text ); if($this->mOptions->getUseDynamicDates()) { - global $wgDateFormatter; - $text = $wgDateFormatter->reformat( $this->mOptions->getDateFormat(), $text ); + $df =& DateFormatter::getInstance(); + $text = $df->reformat( $this->mOptions->getDateFormat(), $text ); } $text = $this->doAllQuotes( $text ); $text = $this->replaceInternalLinks( $text ); @@ -2997,7 +2997,7 @@ class ParserOptions { # All variables are private var $mUseTeX; # Use texvc to expand tags - var $mUseDynamicDates; # Use $wgDateFormatter to format dates + var $mUseDynamicDates; # Use DateFormatter to format dates var $mInterwikiMagic; # Interlanguage links are removed and returned in an array var $mAllowExternalImages; # Allow external images inline var $mSkin; # Reference to the preferred skin diff --git a/includes/Setup.php b/includes/Setup.php index 057181f831..738abb4452 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -72,6 +72,10 @@ require_once( 'HistoryBlob.php' ); require_once( 'ProxyTools.php' ); require_once( 'ObjectCache.php' ); +if ( $wgUseDynamicDates ) { + require_once( 'DateFormatter.php' ); +} + wfProfileOut( $fname.'-includes' ); wfProfileIn( $fname.'-misc1' ); @@ -260,14 +264,6 @@ wfProfileIn( $fname.'-OutputPage' ); $wgOut = new OutputPage(); wfProfileOut( $fname.'-OutputPage' ); -wfProfileIn( $fname.'-DateFormatter' ); - -if ( $wgUseDynamicDates ) { - require_once( 'DateFormatter.php' ); - $wgDateFormatter = new DateFormatter; -} - -wfProfileOut( $fname.'-DateFormatter' ); wfProfileIn( $fname.'-BlockCache' ); $wgBlockCache = new BlockCache( true );