r78926 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78925‎ | r78926 | r78927 >
Date:21:01, 23 December 2010
Author:catrope
Status:ok
Tags:
Comment:
(bug 26399) Preload module info for all modules in startup module, to prevent lots of individual queries. Also improve preloadModuleInfo() to register the absence of message blobs for modules that do have messages (they were being missed because they were expected to have blobs for this reason)
Modified paths:
  • /trunk/phase3/includes/resourceloader/ResourceLoader.php (modified) (history)
  • /trunk/phase3/includes/resourceloader/ResourceLoaderStartUpModule.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/resourceloader/ResourceLoader.php
@@ -51,7 +51,7 @@
5252 * @param $modules Array: List of module names to preload information for
5353 * @param $context ResourceLoaderContext: Context to load the information within
5454 */
55 - protected function preloadModuleInfo( array $modules, ResourceLoaderContext $context ) {
 55+ public function preloadModuleInfo( array $modules, ResourceLoaderContext $context ) {
5656 if ( !count( $modules ) ) {
5757 return; // or else Database*::select() will explode, plus it's cheaper!
5858 }
@@ -82,14 +82,12 @@
8383
8484 // Get message blob mtimes. Only do this for modules with messages
8585 $modulesWithMessages = array();
86 - $modulesWithoutMessages = array();
8786 foreach ( $modules as $name ) {
8887 if ( count( $this->getModule( $name )->getMessages() ) ) {
8988 $modulesWithMessages[] = $name;
90 - } else {
91 - $modulesWithoutMessages[] = $name;
9289 }
9390 }
 91+ $modulesWithoutMessages = array_flip( $modules ); // Will be trimmed down by the loop below
9492 if ( count( $modulesWithMessages ) ) {
9593 $res = $dbr->select( 'msg_resource', array( 'mr_resource', 'mr_timestamp' ), array(
9694 'mr_resource' => $modulesWithMessages,
@@ -98,9 +96,10 @@
9997 );
10098 foreach ( $res as $row ) {
10199 $this->getModule( $row->mr_resource )->setMsgBlobMtime( $lang, $row->mr_timestamp );
 100+ unset( $modulesWithoutMessages[$row->mr_resource] );
102101 }
103 - }
104 - foreach ( $modulesWithoutMessages as $name ) {
 102+ }
 103+ foreach ( array_keys( $modulesWithoutMessages ) as $name ) {
105104 $this->getModule( $name )->setMsgBlobMtime( $lang, 0 );
106105 }
107106 }
Index: trunk/phase3/includes/resourceloader/ResourceLoaderStartUpModule.php
@@ -189,13 +189,17 @@
190190 if ( isset( $this->modifiedTime[$hash] ) ) {
191191 return $this->modifiedTime[$hash];
192192 }
 193+
 194+ // Call preloadModuleInfo() on ALL modules as we're about
 195+ // to call getModifiedTime() on all of them
 196+ $loader = $context->getResourceLoader();
 197+ $loader->preloadModuleInfo( $loader->getModuleNames(), $context );
 198+
193199 $this->modifiedTime[$hash] = filemtime( "$IP/resources/startup.js" );
194 -
195 - // ATTENTION!: Because of the line above, this is not going to cause
 200+ // ATTENTION!: Because of the line above, this is not going to cause
196201 // infinite recursion - think carefully before making changes to this
197202 // code!
198203 $time = wfTimestamp( TS_UNIX, $wgCacheEpoch );
199 - $loader = $context->getResourceLoader();
200204 foreach ( $loader->getModuleNames() as $name ) {
201205 $module = $loader->getModule( $name );
202206 $time = max( $time, $module->getModifiedTime( $context ) );

Follow-up revisions

RevisionCommit summaryAuthorDate
r79129MFT r78011 r78014 r78015 r78016 r78099 r78117 r78161 r78170 r78172 r78199 r78......platonides19:58, 28 December 2010

Status & tagging log