don't load so much stuff on parser cache hit (experimental)
authorTim Starling <tstarling@users.mediawiki.org>
Fri, 4 Jun 2004 10:40:44 +0000 (10:40 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Fri, 4 Jun 2004 10:40:44 +0000 (10:40 +0000)
includes/Article.php
includes/OutputPage.php
includes/ParserCache.php

index 41896ba..9216a68 100644 (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;
+               # 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( '<pre>'.htmlspecialchars($this->mContent)."\n</pre>" );
-               } 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( '<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;
index 1753e58..a9e3e7b 100644 (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;
index b96bff1..9b828b0 100644 (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 );