* In ResourceLoaderContext, lazy-load $this->direction and $this->language, to avoid...
authorTim Starling <tstarling@users.mediawiki.org>
Fri, 19 Nov 2010 06:52:38 +0000 (06:52 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Fri, 19 Nov 2010 06:52:38 +0000 (06:52 +0000)
* 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.

includes/resourceloader/ResourceLoader.php
includes/resourceloader/ResourceLoaderContext.php
includes/resourceloader/ResourceLoaderModule.php

index f27d1e3..5a9d220 100644 (file)
@@ -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
index 8a009e2..56cd90a 100644 (file)
@@ -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
                        ) );
                }
index b60ae7b..3ef4168 100644 (file)
@@ -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];
        }