From: Andrew Garrett Date: Fri, 6 Feb 2009 20:27:58 +0000 (+0000) Subject: Cache preprocessor output in memcached. X-Git-Tag: 1.31.0-rc.0~42998 X-Git-Url: http://git.cyclocoop.org/url?a=commitdiff_plain;h=cc481275ef5f1dd7d85c005c67035372ecc9eac7;p=lhc%2Fweb%2Fwiklou.git Cache preprocessor output in memcached. --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 843e9cfca8..d64659d0ac 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -87,6 +87,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * New function to convert namespace text for display (only applies on wiki with LanguageConverter class) * (bug 17379) Contributions-title is now parsed for magic words. +* Preprocessor output now cached in memcached. === Bug fixes in 1.15 === * (bug 16968) Special:Upload no longer throws useless warnings. diff --git a/includes/parser/Preprocessor_DOM.php b/includes/parser/Preprocessor_DOM.php index 502d81f946..66b5e1d3e3 100644 --- a/includes/parser/Preprocessor_DOM.php +++ b/includes/parser/Preprocessor_DOM.php @@ -63,8 +63,40 @@ class Preprocessor_DOM implements Preprocessor { */ function preprocessToObj( $text, $flags = 0 ) { wfProfileIn( __METHOD__ ); - wfProfileIn( __METHOD__.'-makexml' ); - + + global $wgMemc; + $cacheKey = wfMemcKey( 'preprocess-xml', md5($text), $flags ); + + if ( $xml = $wgMemc->get( $cacheKey ) ) { + // From the cache + wfDebugLog( "Preprocessor", "Loaded preprocessor XML from memcached (key $cacheKey)" ); + } else { + $xml = $this->preprocessToXml( $text, $flags ); + $wgMemc->set( $cacheKey, $xml, 86400 ); + wfDebugLog( "Preprocessor", "Saved preprocessor XML to memcached (key $cacheKey)" ); + } + + wfProfileIn( __METHOD__.'-loadXML' ); + $dom = new DOMDocument; + wfSuppressWarnings(); + $result = $dom->loadXML( $xml ); + wfRestoreWarnings(); + if ( !$result ) { + // Try running the XML through UtfNormal to get rid of invalid characters + $xml = UtfNormal::cleanUp( $xml ); + $result = $dom->loadXML( $xml ); + if ( !$result ) { + throw new MWException( __METHOD__.' generated invalid XML' ); + } + } + $obj = new PPNode_DOM( $dom->documentElement ); + wfProfileOut( __METHOD__.'-loadXML' ); + wfProfileOut( __METHOD__ ); + return $obj; + } + + function preprocessToXml( $text, $flags = 0 ) { + wfProfileIn( __METHOD__ ); $rules = array( '{' => array( 'end' => '}', @@ -571,24 +603,9 @@ class Preprocessor_DOM implements Preprocessor { $stack->rootAccum .= ''; $xml = $stack->rootAccum; - wfProfileOut( __METHOD__.'-makexml' ); - wfProfileIn( __METHOD__.'-loadXML' ); - $dom = new DOMDocument; - wfSuppressWarnings(); - $result = $dom->loadXML( $xml ); - wfRestoreWarnings(); - if ( !$result ) { - // Try running the XML through UtfNormal to get rid of invalid characters - $xml = UtfNormal::cleanUp( $xml ); - $result = $dom->loadXML( $xml ); - if ( !$result ) { - throw new MWException( __METHOD__.' generated invalid XML' ); - } - } - $obj = new PPNode_DOM( $dom->documentElement ); - wfProfileOut( __METHOD__.'-loadXML' ); wfProfileOut( __METHOD__ ); - return $obj; + + return $xml; } } diff --git a/includes/parser/Preprocessor_Hash.php b/includes/parser/Preprocessor_Hash.php index 0e0fb57926..0bebdb7f24 100644 --- a/includes/parser/Preprocessor_Hash.php +++ b/includes/parser/Preprocessor_Hash.php @@ -45,6 +45,15 @@ class Preprocessor_Hash implements Preprocessor { */ function preprocessToObj( $text, $flags = 0 ) { wfProfileIn( __METHOD__ ); + + global $wgMemc; + $cacheKey = wfMemckey( 'preprocessor-hash', md5( $text ), $flags ); + + if ( $obj = $wgMemc->get( $cacheKey ) ) { + wfDebugLog( "Preprocessor", "Got preprocessor_hash output from cache" ); + wfProfileOut( __METHOD__ ); + return $obj; + } $rules = array( '{' => array( @@ -618,6 +627,9 @@ class Preprocessor_Hash implements Preprocessor { $rootNode->firstChild = $stack->rootAccum->firstNode; $rootNode->lastChild = $stack->rootAccum->lastNode; wfProfileOut( __METHOD__ ); + + $wgMemc->set( $cacheKey, $rootNode, 86400 ); + return $rootNode; } }