From: Brian Wolff Date: Fri, 4 Jan 2013 09:11:13 +0000 (-0400) Subject: Reuse the WikiPage object to save a db query X-Git-Tag: 1.31.0-rc.0~21151 X-Git-Url: https://git.cyclocoop.org/%28%28?a=commitdiff_plain;h=9e5802ef66c8a3aef2d7f63eb63c0cd5058f73e8;p=lhc%2Fweb%2Fwiklou.git Reuse the WikiPage object to save a db query Early in the request we call Action::getActionName to get the action name for HTMLFileCache to see if the current action is cached. This causes data to be loaded from the WikiPage object stored in the main request context. However, later when we're initializing the Article object, we overwrite that WikiPage object with the one used by the Article object. Later on the WikiPage object has to be re-loaded, and hence the exact same db request is run twice in one request, which seems wasteful. Instead, initialize the Article object using the WikiPage object from the context, in order to save the already loaded data. Change-Id: I292f0d70feb505fae5fa955fd735d85ad3b22fea --- diff --git a/includes/Wiki.php b/includes/Wiki.php index d4840cc22e..2b12dd76a2 100644 --- a/includes/Wiki.php +++ b/includes/Wiki.php @@ -331,8 +331,18 @@ class MediaWiki { wfProfileIn( __METHOD__ ); $title = $this->context->getTitle(); - $article = Article::newFromTitle( $title, $this->context ); - $this->context->setWikiPage( $article->getPage() ); + if ( $this->context->canUseWikiPage() ) { + // Try to use request context wiki page, as there + // is already data from db saved in per process + // cache there from this->getAction() call. + $page = $this->context->getWikiPage(); + $article = Article::newFromWikiPage( $page, $this->context ); + } else { + // This case should not happen, but just in case. + $article = Article::newFromTitle( $title, $this->context ); + $this->context->setWikiPage( $article->getPage() ); + } + // NS_MEDIAWIKI has no redirects. // It is also used for CSS/JS, so performance matters here... if ( $title->getNamespace() == NS_MEDIAWIKI ) {