From db350f2bf69c6ccc07a0089ff2e65471e48a8135 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Sat, 21 Aug 2004 14:56:07 +0000 Subject: [PATCH] Replaced link holders with actual links before saving into the cache, thereby speeding up parser cache hits. Profiling confirms a marked decrease in cache hit service time --- includes/Article.php | 4 ++-- includes/OutputPage.php | 48 +++++++++++++++++++++++++++++------------ 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index fb2b94e5e6..ec07e3df70 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -741,7 +741,7 @@ class Article { "$link" ); } else if ( $pcache ) { # Display content and save to parser cache - $wgOut->addWikiText( $text, true, $this ); + $wgOut->addPrimaryWikiText( $text, $this ); } else { # Display content, don't attempt to save to parser cache $wgOut->addWikiText( $text ); @@ -760,7 +760,7 @@ class Article { } # Put link titles into the link cache - $wgOut->replaceLinkHolders(); + $wgOut->transformBuffer(); # Add link titles as META keywords $wgOut->addMetaTags() ; diff --git a/includes/OutputPage.php b/includes/OutputPage.php index bd1a01280b..948fc41f26 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -218,25 +218,40 @@ class OutputPage { return wfSetVar( $this->mParserOptions, $options ); } - # First pass--just handle sections, pass the rest off - # to doWikiPass2() which does all the real work. + # Convert wikitext to HTML and add it to the buffer # - # $cacheArticle - assume this text is the main text for the given article - # - function addWikiText( $text, $linestart = true, $cacheArticle = NULL ) + function addWikiText( $text, $linestart = true ) { - global $wgParser, $wgParserCache, $wgUser, $wgTitle; + global $wgParser, $wgTitle; $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions, $linestart ); + $this->mLanguageLinks += $parserOutput->getLanguageLinks(); + $this->mCategoryLinks += $parserOutput->getCategoryLinks(); + $this->addHTML( $parserOutput->getText() ); + } + + # Add wikitext to the buffer, assuming that this is the primary text for a page view + # Saves the text into the parser cache if possible + # + function addPrimaryWikiText( $text, $cacheArticle ) { + global $wgParser, $wgParserCache, $wgUser, $wgTitle; + + $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions, true ); + + # Replace link holders + $text = $parserOutput->getText(); + $this->replaceLinkHolders( $text ); + $parserOutput->setText( $text ); + if ( $cacheArticle ) { $wgParserCache->save( $parserOutput, $cacheArticle, $wgUser ); } $this->mLanguageLinks += $parserOutput->getLanguageLinks(); $this->mCategoryLinks += $parserOutput->getCategoryLinks(); - $this->addHTML( $parserOutput->getText() ); + $this->addHTML( $text ); } - + function tryParserCache( $article, $user ) { global $wgParserCache; $parserOutput = $wgParserCache->get( $article, $user ); @@ -352,7 +367,7 @@ class OutputPage { $this->sendCacheControl(); # Perform link colouring - $this->replaceLinkHolders(); + $this->transformBuffer(); # Disable temporary placeholders, so that the skin produces HTML $sk->postParseLinkColour( false ); @@ -762,6 +777,12 @@ class OutputPage { return $ret; } + # Run any necessary pre-output transformations on the buffer text + function transformBuffer( $options = 0 ) + { + $this->replaceLinkHolders( $this->mBodytext, $options ); + } + # Replace link placeholders with actual links, in the buffer # Placeholders created in Skin::makeLinkObj() # Returns an array of links found, indexed by PDBK: @@ -769,8 +790,7 @@ class OutputPage { # 1 - normal link # 2 - stub # $options is a bit field, RLH_FOR_UPDATE to select for update - function replaceLinkHolders( $options = 0 ) - { + function replaceLinkHolders( &$text, $options = 0 ) { global $wgUser, $wgLinkCache, $wgUseOldExistenceCheck; if ( $wgUseOldExistenceCheck ) { @@ -786,7 +806,7 @@ class OutputPage { # Get placeholders from body wfProfileIn( "$fname-match" ); - preg_match_all( "//", $this->mBodytext, $tmpLinks ); + preg_match_all( "//", $text, $tmpLinks ); wfProfileOut( "$fname-match" ); if ( !empty( $tmpLinks[0] ) ) { @@ -896,10 +916,10 @@ class OutputPage { # Do the thing wfProfileIn( "$fname-replace" ); - $this->mBodytext = preg_replace_callback( + $text = preg_replace_callback( '/()/', "outputReplaceMatches", - $this->mBodytext); + $text); wfProfileOut( "$fname-replace" ); } wfProfileOut( $fname ); -- 2.20.1