From: Tim Starling Date: Fri, 4 Jun 2004 10:40:44 +0000 (+0000) Subject: don't load so much stuff on parser cache hit (experimental) X-Git-Tag: 1.5.0alpha1~3043 X-Git-Url: https://git.cyclocoop.org/%28%28?a=commitdiff_plain;h=e7ac88064a37a32a935e4624edab23f22cf6881f;p=lhc%2Fweb%2Fwiklou.git don't load so much stuff on parser cache hit (experimental) --- diff --git a/includes/Article.php b/includes/Article.php index 41896ba55c..9216a68ca8 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -538,48 +538,67 @@ class Article { return; } } - - $text = $this->getContent( false ); # May change mTitle by following a redirect - # Another whitelist check in case oldid or redirects are altering the title - if ( !$this->mTitle->userCanRead() ) { - $wgOut->loginToUse(); - $wgOut->output(); - exit; + # Should the parser cache be used? + if ( $wgEnableParserCache && intval($wgUser->getOption( "stubthreshold" )) == 0 && empty( $oldid ) ) { + $pcache = true; + } else { + $pcache = false; } - $wgOut->setPageTitle( $this->mTitle->getPrefixedText() ); + $outputDone = false; + if ( $pcache ) { + if ( $wgOut->tryParserCache( $this, $wgUser ) ) { + $outputDone = true; + } + } - # We're looking at an old revision + if ( !$outputDone ) { + $text = $this->getContent( false ); # May change mTitle by following a redirect + + # Another whitelist check in case oldid or redirects are altering the title + if ( !$this->mTitle->userCanRead() ) { + $wgOut->loginToUse(); + $wgOut->output(); + exit; + } + + $wgOut->setPageTitle( $this->mTitle->getPrefixedText() ); - if ( !empty( $oldid ) ) { - $this->setOldSubtitle(); - $wgOut->setRobotpolicy( "noindex,follow" ); - } - if ( "" != $this->mRedirectedFrom ) { - $sk = $wgUser->getSkin(); - $redir = $sk->makeKnownLink( $this->mRedirectedFrom, "", - "redirect=no" ); - $s = wfMsg( "redirectedfrom", $redir ); - $wgOut->setSubtitle( $s ); - } + # We're looking at an old revision - $wgLinkCache->preFill( $this->mTitle ); + if ( !empty( $oldid ) ) { + $this->setOldSubtitle(); + $wgOut->setRobotpolicy( "noindex,follow" ); + } + if ( "" != $this->mRedirectedFrom ) { + $sk = $wgUser->getSkin(); + $redir = $sk->makeKnownLink( $this->mRedirectedFrom, "", + "redirect=no" ); + $s = wfMsg( "redirectedfrom", $redir ); + $wgOut->setSubtitle( $s ); + + # Can't cache redirects + $pcache = false; + } - # wrap user css and user js in pre and don't parse - # XXX: use $this->mTitle->usCssJsSubpage() when php is fixed/ a workaround is found - if ( - $this->mTitle->getNamespace() == Namespace::getUser() && - preg_match("/\\/[\\w]+\\.(css|js)$/", $this->mTitle->getDBkey()) - ) { - $wgOut->addWikiText( wfMsg('usercssjs')); - $wgOut->addHTML( '
'.htmlspecialchars($this->mContent)."\n
" ); - } else if( $wgEnableParserCache && intval($wgUser->getOption( "stubthreshold" )) == 0 && empty( $oldid ) ){ - $wgOut->addWikiText( $text, true, $this ); - } else { - $wgOut->addWikiText( $text ); + $wgLinkCache->preFill( $this->mTitle ); + + # wrap user css and user js in pre and don't parse + # XXX: use $this->mTitle->usCssJsSubpage() when php is fixed/ a workaround is found + if ( + $this->mTitle->getNamespace() == Namespace::getUser() && + preg_match("/\\/[\\w]+\\.(css|js)$/", $this->mTitle->getDBkey()) + ) { + $wgOut->addWikiText( wfMsg('usercssjs')); + $wgOut->addHTML( '
'.htmlspecialchars($this->mContent)."\n
" ); + } else if ( $pcache ) { + $wgOut->addWikiText( $text, true, $this ); + } else { + $wgOut->addWikiText( $text ); + } } - + # Add link titles as META keywords $wgOut->addMetaTags() ; @@ -1507,6 +1526,7 @@ class Article { and (!$this->mRedirectedFrom); } + # Loads cur_touched and returns a value indicating if it should be used function checkTouched() { $id = $this->getID(); $sql = "SELECT cur_touched,cur_is_redirect FROM cur WHERE cur_id=$id"; @@ -1519,10 +1539,6 @@ class Article { } } - function getTouched() { - return $this->mTouched; - } - # Edit an article without doing all that other stuff function quickEdit( $text, $comment = "", $minor = 0 ) { global $wgUser, $wgMwRedir; diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 1753e58ba5..a9e3e7bd86 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -208,26 +208,29 @@ class OutputPage { function addWikiText( $text, $linestart = true, $cacheArticle = NULL ) { global $wgParser, $wgParserCache, $wgUser, $wgTitle; - - $parserOutput = false; + + $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions, $linestart ); if ( $cacheArticle ) { - $parserOutput = $wgParserCache->get( $cacheArticle, $wgUser ); - } - - if ( $parserOutput === false ) { - $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions, $linestart ); - if ( $cacheArticle ) { - $wgParserCache->save( $parserOutput, $cacheArticle, $wgUser ); - } + $wgParserCache->save( $parserOutput, $cacheArticle, $wgUser ); } $this->mLanguageLinks += $parserOutput->getLanguageLinks(); $this->mCategoryLinks += $parserOutput->getCategoryLinks(); - $this->addHTML( $parserOutput->getText() ); - } + function tryParserCache( $article, $user ) { + $parserOutput = $wgParserCache->get( $article, $user ); + if ( $parserOutput !== false ) { + $this->mLanguageLinks += $parserOutput->getLanguageLinks(); + $this->mCategoryLinks += $parserOutput->getCategoryLinks(); + $this->addHTML( $parserOutput->getText() ); + return true; + } else { + return false; + } + } + # Set the maximum cache time on the Squid in seconds function setSquidMaxage( $maxage ) { $this->mSquidMaxage = $maxage; diff --git a/includes/ParserCache.php b/includes/ParserCache.php index b96bff1121..9b828b0124 100644 --- a/includes/ParserCache.php +++ b/includes/ParserCache.php @@ -23,10 +23,14 @@ class ParserCache if ( $value ) { wfDebug( "Found.\n" ); # Delete if article has changed since the cache was made - $touched = $article->getTouched(); + $canCache = $article->checkTouched(); $cacheTime = $value->getCacheTime(); - if ( $value->getCacheTime() <= $touched || $cacheTime < $wgCacheEpoch ) { - wfDebug( "Key expired, touched $touched, epoch $wgCacheEpoch, cached $cacheTime\n" ); + if ( !$canCache || $value->getCacheTime() <= $touched || $cacheTime < $wgCacheEpoch ) { + if ( !$canCache ) { + wfDebug( "Invalid cached redirect, touched $touched, epoch $wgCacheEpoch, cached $cacheTime\n" ); + } else { + wfDebug( "Key expired, touched $touched, epoch $wgCacheEpoch, cached $cacheTime\n" ); + } $wgMemc->delete( $key ); $value = false; } @@ -40,6 +44,7 @@ class ParserCache function save( $parserOutput, &$article, &$user ){ global $wgMemc; + $key = $this->getKey( $article, $user ); $now = wfTimestampNow(); $parserOutput->setCacheTime( $now );