Index: trunk/phase3/includes/parser/Preprocessor_Hash.php |
— | — | @@ -45,6 +45,15 @@ |
46 | 46 | */ |
47 | 47 | function preprocessToObj( $text, $flags = 0 ) { |
48 | 48 | 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 | + } |
49 | 58 | |
50 | 59 | $rules = array( |
51 | 60 | '{' => array( |
— | — | @@ -618,6 +627,9 @@ |
619 | 628 | $rootNode->firstChild = $stack->rootAccum->firstNode; |
620 | 629 | $rootNode->lastChild = $stack->rootAccum->lastNode; |
621 | 630 | wfProfileOut( __METHOD__ ); |
| 631 | + |
| 632 | + $wgMemc->set( $cacheKey, $rootNode, 86400 ); |
| 633 | + |
622 | 634 | return $rootNode; |
623 | 635 | } |
624 | 636 | } |
Index: trunk/phase3/includes/parser/Preprocessor_DOM.php |
— | — | @@ -63,8 +63,40 @@ |
64 | 64 | */ |
65 | 65 | function preprocessToObj( $text, $flags = 0 ) { |
66 | 66 | 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__ ); |
69 | 101 | $rules = array( |
70 | 102 | '{' => array( |
71 | 103 | 'end' => '}', |
— | — | @@ -571,24 +603,9 @@ |
572 | 604 | $stack->rootAccum .= '</root>'; |
573 | 605 | $xml = $stack->rootAccum; |
574 | 606 | |
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' ); |
591 | 607 | wfProfileOut( __METHOD__ ); |
592 | | - return $obj; |
| 608 | + |
| 609 | + return $xml; |
593 | 610 | } |
594 | 611 | } |
595 | 612 | |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -87,6 +87,7 @@ |
88 | 88 | * New function to convert namespace text for display (only applies on wiki with |
89 | 89 | LanguageConverter class) |
90 | 90 | * (bug 17379) Contributions-title is now parsed for magic words. |
| 91 | +* Preprocessor output now cached in memcached. |
91 | 92 | |
92 | 93 | === Bug fixes in 1.15 === |
93 | 94 | * (bug 16968) Special:Upload no longer throws useless warnings. |