From 9e5802ef66c8a3aef2d7f63eb63c0cd5058f73e8 Mon Sep 17 00:00:00 2001 From: Brian Wolff Date: Fri, 4 Jan 2013 05:11:13 -0400 Subject: [PATCH] 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 --- includes/Wiki.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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 ) { -- 2.20.1