MediaWiki: Don't eagerly initialize action name
main() calls getAction() eagerly as it may be used by the file cache if it is enabled. However, getAction() is expensive as it will trigger memcached I/O and DB queries, and the file cache is disabled by default (and by large installations such as Wikimedia). This can result in unnecessary I/O on requests that abort early due to tryNormaliseRedirect() or a MediaWikiPerformAction / BeforeInitialize hook handler. So, call getAction() early only if the file cache is actually in use. This avoids the upfront cost of initializing a full WikiPage object for requests that will not use it. Change-Id: I72ffc9f36613bf9de0b3d95276435d08a8a65df4
This commit is contained in:
parent
09b92847f8
commit
d7beb0e4ec
1 changed files with 6 additions and 4 deletions
|
|
@ -417,9 +417,8 @@ class MediaWiki {
|
|||
$title = $this->context->getTitle();
|
||||
$services = MediaWikiServices::getInstance();
|
||||
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.
|
||||
// Reuse the WikiPage instance from context, as it may already have been initialized
|
||||
// by an earlier this->getAction() call.
|
||||
$page = $this->context->getWikiPage();
|
||||
} else {
|
||||
// This case should not happen, but just in case.
|
||||
|
|
@ -870,7 +869,6 @@ class MediaWiki {
|
|||
// Get title from request parameters,
|
||||
// is set on the fly by parseTitle the first time.
|
||||
$title = $this->getTitle();
|
||||
$action = $this->getAction();
|
||||
$wgTitle = $title;
|
||||
|
||||
// Set DB query expectations for this HTTP request
|
||||
|
|
@ -888,6 +886,10 @@ class MediaWiki {
|
|||
}
|
||||
|
||||
if ( $title->canExist() && HTMLFileCache::useFileCache( $this->context ) ) {
|
||||
// getAction() may trigger DB queries, so avoid eagerly initializing it if possible.
|
||||
// This reduces the cost of requests that exit early due to tryNormaliseRedirect()
|
||||
// or a MediaWikiPerformAction / BeforeInitialize hook handler.
|
||||
$action = $this->getAction();
|
||||
// Try low-level file cache hit
|
||||
$cache = new HTMLFileCache( $title, $action );
|
||||
if ( $cache->isCacheGood( /* Assume up to date */ ) ) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue