From 03dfa9f60c61f0c10af58618e837fb771bd61223 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Mon, 3 Jan 2011 19:50:01 +0000 Subject: [PATCH] * Modified Article::loadPageData() to use a slave database connection and pageDataFromTitle() instead of pageDataFromId() in the default case, as in Wiki.php (this also saves a query since the ID will be fetched with other fileds) * 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 | 35 +++++++++++++++++------------------ includes/Wiki.php | 5 +---- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index d4445cefd2..3355b0138d 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -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; } diff --git a/includes/Wiki.php b/includes/Wiki.php index c0cdb5389e..884156fd96 100644 --- a/includes/Wiki.php +++ b/includes/Wiki.php @@ -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; -- 2.20.1