r46936 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r46935‎ | r46936 | r46937 >
Date:20:27, 6 February 2009
Author:werdna
Status:ok (Comments)
Tags:
Comment:
Cache preprocessor output in memcached.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/parser/Preprocessor_DOM.php (modified) (history)
  • /trunk/phase3/includes/parser/Preprocessor_Hash.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/Preprocessor_Hash.php
@@ -45,6 +45,15 @@
4646 */
4747 function preprocessToObj( $text, $flags = 0 ) {
4848 wfProfileIn( __METHOD__ );
 49+
 50+ global $wgMemc;
 51+ $cacheKey = wfMemckey( 'preprocessor-hash', md5( $text ), $flags );
 52+
 53+ if ( $obj = $wgMemc->get( $cacheKey ) ) {
 54+ wfDebugLog( "Preprocessor", "Got preprocessor_hash output from cache" );
 55+ wfProfileOut( __METHOD__ );
 56+ return $obj;
 57+ }
4958
5059 $rules = array(
5160 '{' => array(
@@ -618,6 +627,9 @@
619628 $rootNode->firstChild = $stack->rootAccum->firstNode;
620629 $rootNode->lastChild = $stack->rootAccum->lastNode;
621630 wfProfileOut( __METHOD__ );
 631+
 632+ $wgMemc->set( $cacheKey, $rootNode, 86400 );
 633+
622634 return $rootNode;
623635 }
624636 }
Index: trunk/phase3/includes/parser/Preprocessor_DOM.php
@@ -63,8 +63,40 @@
6464 */
6565 function preprocessToObj( $text, $flags = 0 ) {
6666 wfProfileIn( __METHOD__ );
67 - wfProfileIn( __METHOD__.'-makexml' );
68 -
 67+
 68+ global $wgMemc;
 69+ $cacheKey = wfMemcKey( 'preprocess-xml', md5($text), $flags );
 70+
 71+ if ( $xml = $wgMemc->get( $cacheKey ) ) {
 72+ // From the cache
 73+ wfDebugLog( "Preprocessor", "Loaded preprocessor XML from memcached (key $cacheKey)" );
 74+ } else {
 75+ $xml = $this->preprocessToXml( $text, $flags );
 76+ $wgMemc->set( $cacheKey, $xml, 86400 );
 77+ wfDebugLog( "Preprocessor", "Saved preprocessor XML to memcached (key $cacheKey)" );
 78+ }
 79+
 80+ wfProfileIn( __METHOD__.'-loadXML' );
 81+ $dom = new DOMDocument;
 82+ wfSuppressWarnings();
 83+ $result = $dom->loadXML( $xml );
 84+ wfRestoreWarnings();
 85+ if ( !$result ) {
 86+ // Try running the XML through UtfNormal to get rid of invalid characters
 87+ $xml = UtfNormal::cleanUp( $xml );
 88+ $result = $dom->loadXML( $xml );
 89+ if ( !$result ) {
 90+ throw new MWException( __METHOD__.' generated invalid XML' );
 91+ }
 92+ }
 93+ $obj = new PPNode_DOM( $dom->documentElement );
 94+ wfProfileOut( __METHOD__.'-loadXML' );
 95+ wfProfileOut( __METHOD__ );
 96+ return $obj;
 97+ }
 98+
 99+ function preprocessToXml( $text, $flags = 0 ) {
 100+ wfProfileIn( __METHOD__ );
69101 $rules = array(
70102 '{' => array(
71103 'end' => '}',
@@ -571,24 +603,9 @@
572604 $stack->rootAccum .= '</root>';
573605 $xml = $stack->rootAccum;
574606
575 - wfProfileOut( __METHOD__.'-makexml' );
576 - wfProfileIn( __METHOD__.'-loadXML' );
577 - $dom = new DOMDocument;
578 - wfSuppressWarnings();
579 - $result = $dom->loadXML( $xml );
580 - wfRestoreWarnings();
581 - if ( !$result ) {
582 - // Try running the XML through UtfNormal to get rid of invalid characters
583 - $xml = UtfNormal::cleanUp( $xml );
584 - $result = $dom->loadXML( $xml );
585 - if ( !$result ) {
586 - throw new MWException( __METHOD__.' generated invalid XML' );
587 - }
588 - }
589 - $obj = new PPNode_DOM( $dom->documentElement );
590 - wfProfileOut( __METHOD__.'-loadXML' );
591607 wfProfileOut( __METHOD__ );
592 - return $obj;
 608+
 609+ return $xml;
593610 }
594611 }
595612
Index: trunk/phase3/RELEASE-NOTES
@@ -87,6 +87,7 @@
8888 * New function to convert namespace text for display (only applies on wiki with
8989 LanguageConverter class)
9090 * (bug 17379) Contributions-title is now parsed for magic words.
 91+* Preprocessor output now cached in memcached.
9192
9293 === Bug fixes in 1.15 ===
9394 * (bug 16968) Special:Upload no longer throws useless warnings.

Follow-up revisions

RevisionCommit summaryAuthorDate
r47065Apply changes made live on Wikimedia cluster related to preprocessor caching ...werdna23:18, 9 February 2009

Comments

#Comment by Aaron Schulz (talk | contribs)   13:44, 9 February 2009

I don't think this is compatible with FlaggedRevs. Some settable parser instance flag to not used it may be needed.

#Comment by Werdna (talk | contribs)   18:48, 9 February 2009

Be more specific, please. What does it do that is "incompatible" with FlaggedRevs?

#Comment by Aaron Schulz (talk | contribs)   20:16, 9 February 2009

Anything that uses the template/image fetching hooks will be ignored on cache hits, so FlaggedRevs can't pick the included item versions.

#Comment by Werdna (talk | contribs)   20:59, 9 February 2009

Those hooks are not called during preprocessing.

#Comment by Aaron Schulz (talk | contribs)   11:12, 10 February 2009

Looks OK

#Comment by Werdna (talk | contribs)   23:23, 9 February 2009

This revision was revamped in r47065.

Status & tagging log