From: Tim Starling Date: Fri, 19 Nov 2010 06:52:38 +0000 (+0000) Subject: * In ResourceLoaderContext, lazy-load $this->direction and $this->language, to avoid... X-Git-Tag: 1.31.0-rc.0~33814 X-Git-Url: http://git.cyclocoop.org/%24href?a=commitdiff_plain;h=ec2acb239b4ece2c55b06869a4b7978e7fe4ab19;p=lhc%2Fweb%2Fwiklou.git * In ResourceLoaderContext, lazy-load $this->direction and $this->language, to avoid loading the whole English localisation for load.php requests which never call getHash(). * Interpreted some Trevor-speak in the doc comment of ResourceLoader::preloadModuleInfo(). * Made setMsgBlobMtime() (called from preloadModuleInfo()) actually work, by making getMsgBlobMtime() use the cached blob times if they are available. --- diff --git a/includes/resourceloader/ResourceLoader.php b/includes/resourceloader/ResourceLoader.php index f27d1e36ca..5a9d22059c 100644 --- a/includes/resourceloader/ResourceLoader.php +++ b/includes/resourceloader/ResourceLoader.php @@ -41,9 +41,9 @@ class ResourceLoader { * This method grabs modules dependencies from the database and updates modules * objects. * - * This is not inside the module code because it's so much more performant to + * This is not inside the module code because it is much faster to * request all of the information at once than it is to have each module - * requests its own information. This sacrifice of modularity yields a profound + * requests its own information. This sacrifice of modularity yields a substantial * performance improvement. * * @param $modules Array: List of module names to preload information for diff --git a/includes/resourceloader/ResourceLoaderContext.php b/includes/resourceloader/ResourceLoaderContext.php index 8a009e2277..56cd90ab53 100644 --- a/includes/resourceloader/ResourceLoaderContext.php +++ b/includes/resourceloader/ResourceLoaderContext.php @@ -53,23 +53,12 @@ class ResourceLoaderContext { $modules = $request->getVal( 'modules' ); $this->modules = $modules ? explode( '|', $modules ) : array(); // Various parameters - $this->language = $request->getVal( 'lang' ); - $this->direction = $request->getVal( 'dir' ); $this->skin = $request->getVal( 'skin' ); $this->user = $request->getVal( 'user' ); $this->debug = $request->getFuzzyBool( 'debug', $wgResourceLoaderDebug ); $this->only = $request->getVal( 'only' ); $this->version = $request->getVal( 'version' ); - // Fallback on system defaults - if ( !$this->language ) { - $this->language = $wgLang->getCode(); - } - - if ( !$this->direction ) { - $this->direction = Language::factory( $this->language )->getDir(); - } - if ( !$this->skin ) { $this->skin = $wgDefaultSkin; } @@ -88,10 +77,23 @@ class ResourceLoaderContext { } public function getLanguage() { + if ( $this->language === null ) { + global $wgLang; + $this->language = $this->request->getVal( 'lang' ); + if ( !$this->language ) { + $this->language = $wgLang->getCode(); + } + } return $this->language; } public function getDirection() { + if ( $this->direction === null ) { + $this->direction = $this->request->getVal( 'dir' ); + if ( !$this->direction ) { + $this->direction = Language::factory( $this->language )->getDir(); + } + } return $this->direction; } @@ -130,7 +132,7 @@ class ResourceLoaderContext { public function getHash() { if ( isset( $this->hash ) ) { $this->hash = implode( '|', array( - $this->language, $this->direction, $this->skin, $this->user, + $this->getLanguage(), $this->getDirection(), $this->skin, $this->user, $this->debug, $this->only, $this->version ) ); } diff --git a/includes/resourceloader/ResourceLoaderModule.php b/includes/resourceloader/ResourceLoaderModule.php index b60ae7b4f2..3ef4168011 100644 --- a/includes/resourceloader/ResourceLoaderModule.php +++ b/includes/resourceloader/ResourceLoaderModule.php @@ -182,16 +182,18 @@ abstract class ResourceLoaderModule { * @return Integer: UNIX timestamp, or 0 if no blob found */ public function getMsgBlobMtime( $lang ) { - if ( !count( $this->getMessages() ) ) - return 0; - - $dbr = wfGetDB( DB_SLAVE ); - $msgBlobMtime = $dbr->selectField( 'msg_resource', 'mr_timestamp', array( - 'mr_resource' => $this->getName(), - 'mr_lang' => $lang - ), __METHOD__ - ); - $this->msgBlobMtime[$lang] = $msgBlobMtime ? wfTimestamp( TS_UNIX, $msgBlobMtime ) : 0; + if ( !isset( $this->msgBlobMtime[$lang] ) ) { + if ( !count( $this->getMessages() ) ) + return 0; + + $dbr = wfGetDB( DB_SLAVE ); + $msgBlobMtime = $dbr->selectField( 'msg_resource', 'mr_timestamp', array( + 'mr_resource' => $this->getName(), + 'mr_lang' => $lang + ), __METHOD__ + ); + $this->msgBlobMtime[$lang] = $msgBlobMtime ? wfTimestamp( TS_UNIX, $msgBlobMtime ) : 0; + } return $this->msgBlobMtime[$lang]; }