r77010 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r77009‎ | r77010 | r77011 >
Date:06:52, 19 November 2010
Author:tstarling
Status:ok
Tags:
Comment:
* 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.
Modified paths:
  • /trunk/phase3/includes/resourceloader/ResourceLoader.php (modified) (history)
  • /trunk/phase3/includes/resourceloader/ResourceLoaderContext.php (modified) (history)
  • /trunk/phase3/includes/resourceloader/ResourceLoaderModule.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/resourceloader/ResourceLoader.php
@@ -41,9 +41,9 @@
4242 * This method grabs modules dependencies from the database and updates modules
4343 * objects.
4444 *
45 - * This is not inside the module code because it's so much more performant to
 45+ * This is not inside the module code because it is much faster to
4646 * request all of the information at once than it is to have each module
47 - * requests its own information. This sacrifice of modularity yields a profound
 47+ * requests its own information. This sacrifice of modularity yields a substantial
4848 * performance improvement.
4949 *
5050 * @param $modules Array: List of module names to preload information for
Index: trunk/phase3/includes/resourceloader/ResourceLoaderContext.php
@@ -53,23 +53,12 @@
5454 $modules = $request->getVal( 'modules' );
5555 $this->modules = $modules ? explode( '|', $modules ) : array();
5656 // Various parameters
57 - $this->language = $request->getVal( 'lang' );
58 - $this->direction = $request->getVal( 'dir' );
5957 $this->skin = $request->getVal( 'skin' );
6058 $this->user = $request->getVal( 'user' );
6159 $this->debug = $request->getFuzzyBool( 'debug', $wgResourceLoaderDebug );
6260 $this->only = $request->getVal( 'only' );
6361 $this->version = $request->getVal( 'version' );
6462
65 - // Fallback on system defaults
66 - if ( !$this->language ) {
67 - $this->language = $wgLang->getCode();
68 - }
69 -
70 - if ( !$this->direction ) {
71 - $this->direction = Language::factory( $this->language )->getDir();
72 - }
73 -
7463 if ( !$this->skin ) {
7564 $this->skin = $wgDefaultSkin;
7665 }
@@ -88,10 +77,23 @@
8978 }
9079
9180 public function getLanguage() {
 81+ if ( $this->language === null ) {
 82+ global $wgLang;
 83+ $this->language = $this->request->getVal( 'lang' );
 84+ if ( !$this->language ) {
 85+ $this->language = $wgLang->getCode();
 86+ }
 87+ }
9288 return $this->language;
9389 }
9490
9591 public function getDirection() {
 92+ if ( $this->direction === null ) {
 93+ $this->direction = $this->request->getVal( 'dir' );
 94+ if ( !$this->direction ) {
 95+ $this->direction = Language::factory( $this->language )->getDir();
 96+ }
 97+ }
9698 return $this->direction;
9799 }
98100
@@ -130,7 +132,7 @@
131133 public function getHash() {
132134 if ( isset( $this->hash ) ) {
133135 $this->hash = implode( '|', array(
134 - $this->language, $this->direction, $this->skin, $this->user,
 136+ $this->getLanguage(), $this->getDirection(), $this->skin, $this->user,
135137 $this->debug, $this->only, $this->version
136138 ) );
137139 }
Index: trunk/phase3/includes/resourceloader/ResourceLoaderModule.php
@@ -182,16 +182,18 @@
183183 * @return Integer: UNIX timestamp, or 0 if no blob found
184184 */
185185 public function getMsgBlobMtime( $lang ) {
186 - if ( !count( $this->getMessages() ) )
187 - return 0;
188 -
189 - $dbr = wfGetDB( DB_SLAVE );
190 - $msgBlobMtime = $dbr->selectField( 'msg_resource', 'mr_timestamp', array(
191 - 'mr_resource' => $this->getName(),
192 - 'mr_lang' => $lang
193 - ), __METHOD__
194 - );
195 - $this->msgBlobMtime[$lang] = $msgBlobMtime ? wfTimestamp( TS_UNIX, $msgBlobMtime ) : 0;
 186+ if ( !isset( $this->msgBlobMtime[$lang] ) ) {
 187+ if ( !count( $this->getMessages() ) )
 188+ return 0;
 189+
 190+ $dbr = wfGetDB( DB_SLAVE );
 191+ $msgBlobMtime = $dbr->selectField( 'msg_resource', 'mr_timestamp', array(
 192+ 'mr_resource' => $this->getName(),
 193+ 'mr_lang' => $lang
 194+ ), __METHOD__
 195+ );
 196+ $this->msgBlobMtime[$lang] = $msgBlobMtime ? wfTimestamp( TS_UNIX, $msgBlobMtime ) : 0;
 197+ }
196198 return $this->msgBlobMtime[$lang];
197199 }
198200

Status & tagging log