* Modified Article::loadPageData() to use a slave database connection and pageDataFro...
authorAlexandre Emsenhuber <ialex@users.mediawiki.org>
Mon, 3 Jan 2011 19:50:01 +0000 (19:50 +0000)
committerAlexandre Emsenhuber <ialex@users.mediawiki.org>
Mon, 3 Jan 2011 19:50:01 +0000 (19:50 +0000)
* Removed the loadPageData() call for the initial article in Wiki.php, will be triggered by the isRedirect() call 7 lines below if needed (this was not needed if $target is set by the InitializeArticleMaybeRedirect hook), but kept the second one (same as above, Article::exists() triggers Title::getArticleId() that would use one query to get id and a second one is needed to get the complete page data)
* Modified Article::fetchContent() to use common code (loadPageData()) and to only call it if really needed

includes/Article.php
includes/Wiki.php

index d4445ce..3355b01 100644 (file)
@@ -468,8 +468,8 @@ class Article {
         */
        public function loadPageData( $data = 'fromdb' ) {
                if ( $data === 'fromdb' ) {
-                       $dbr = wfGetDB( DB_MASTER );
-                       $data = $this->pageDataFromId( $dbr, $this->getId() );
+                       $dbr = wfGetDB( DB_SLAVE );
+                       $data = $this->pageDataFromTitle( $dbr, $this->mTitle );
                }
 
                $lc = LinkCache::singleton();
@@ -506,8 +506,6 @@ class Article {
                        return $this->mContent;
                }
 
-               $dbr = wfGetDB( DB_MASTER );
-
                # Pre-fill content with error message so that if something
                # fails we'll have something telling us what we intended.
                $t = $this->mTitle->getPrefixedText();
@@ -521,28 +519,29 @@ class Article {
                                return false;
                        }
 
-                       $data = $this->pageDataFromId( $dbr, $revision->getPage() );
-
-                       if ( !$data ) {
-                               wfDebug( __METHOD__ . " failed to get page data linked to revision id $oldid\n" );
-                               return false;
-                       }
-
-                       $this->mTitle = Title::makeTitle( $data->page_namespace, $data->page_title );
-                       $this->loadPageData( $data );
-               } else {
-                       if ( !$this->mDataLoaded ) {
-                               $data = $this->pageDataFromTitle( $dbr, $this->mTitle );
+                       if ( !$this->mDataLoaded || $this->getID() != $revision->getPage() ) {
+                               $data = $this->pageDataFromId( wfGetDB( DB_SLAVE ), $revision->getPage() );
 
                                if ( !$data ) {
-                                       wfDebug( __METHOD__ . " failed to find page data for title " . $this->mTitle->getPrefixedText() . "\n" );
+                                       wfDebug( __METHOD__ . " failed to get page data linked to revision id $oldid\n" );
                                        return false;
                                }
 
+                               $this->mTitle = Title::makeTitle( $data->page_namespace, $data->page_title );
                                $this->loadPageData( $data );
                        }
+               } else {
+                       if ( !$this->mDataLoaded ) {
+                               $this->loadPageData();
+                       }
+
+                       if ( $this->mLatest === false ) {
+                               wfDebug( __METHOD__ . " failed to find page data for title " . $this->mTitle->getPrefixedText() . "\n" );
+                               return false;
+                       }
+
                        $revision = Revision::newFromId( $this->mLatest );
-                       if (  $revision === null ) {
+                       if ( $revision === null ) {
                                wfDebug( __METHOD__ . " failed to retrieve current page, rev_id {$this->mLatest}\n" );
                                return false;
                        }
index c0cdb53..884156f 100644 (file)
@@ -349,9 +349,6 @@ class MediaWiki {
                        // Give extensions a change to ignore/handle redirects as needed
                        $ignoreRedirect = $target = false;
 
-                       $dbr = wfGetDB( DB_SLAVE );
-                       $article->loadPageData( $article->pageDataFromTitle( $dbr, $title ) );
-
                        wfRunHooks( 'InitializeArticleMaybeRedirect',
                                array(&$title,&$request,&$ignoreRedirect,&$target,&$article) );
 
@@ -370,7 +367,7 @@ class MediaWiki {
                                if( is_object($target) ) {
                                        // Rewrite environment to redirected article
                                        $rarticle = self::articleFromTitle( $target );
-                                       $rarticle->loadPageData( $rarticle->pageDataFromTitle( $dbr, $target ) );
+                                       $rarticle->loadPageData();
                                        if( $rarticle->exists() || ( is_object( $file ) && !$file->isLocal() ) ) {
                                                $rarticle->setRedirectedFrom( $title );
                                                $article = $rarticle;