don't load so much stuff on parser cache hit (experimental)

This commit is contained in:
Tim Starling 2004-06-04 10:40:44 +00:00
parent e54370983e
commit e7ac88064a
3 changed files with 81 additions and 57 deletions

View file

@ -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;
}
$wgOut->setPageTitle( $this->mTitle->getPrefixedText() );
# We're looking at an old revision
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 );
}
$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( '<pre>'.htmlspecialchars($this->mContent)."\n</pre>" );
} else if( $wgEnableParserCache && intval($wgUser->getOption( "stubthreshold" )) == 0 && empty( $oldid ) ){
$wgOut->addWikiText( $text, true, $this );
# Should the parser cache be used?
if ( $wgEnableParserCache && intval($wgUser->getOption( "stubthreshold" )) == 0 && empty( $oldid ) ) {
$pcache = true;
} else {
$wgOut->addWikiText( $text );
$pcache = false;
}
$outputDone = false;
if ( $pcache ) {
if ( $wgOut->tryParserCache( $this, $wgUser ) ) {
$outputDone = true;
}
}
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() );
# We're looking at an old revision
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;
}
$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( '<pre>'.htmlspecialchars($this->mContent)."\n</pre>" );
} 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;

View file

@ -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;

View file

@ -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 );