r88125 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r88124‎ | r88125 | r88126 >
Date:23:12, 14 May 2011
Author:tparscal
Status:resolved (Comments)
Tags:
Comment:
Removed the go() call, and the suspended until go() is called behavior.
Modified paths:
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/resources/mediawiki/mediawiki.js (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/OutputPage.php
@@ -2580,9 +2580,7 @@
25812581 if ( $modules ) {
25822582 $scripts .= Html::inlineScript(
25832583 ResourceLoader::makeLoaderConditionalScript(
2584 - Xml::encodeJsCall( 'mw.loader.load', array( $modules ) ) .
2585 - // the go() call is unnecessary if we inserted top modules, but we don't know for sure that we did
2586 - Xml::encodeJsCall( 'mw.loader.go', array() )
 2584+ Xml::encodeJsCall( 'mw.loader.load', array( $modules ) )
25872585 )
25882586 );
25892587 }
Index: trunk/phase3/resources/mediawiki/mediawiki.js
@@ -582,8 +582,6 @@
583583 var queue = [];
584584 // List of callback functions waiting for modules to be ready to be called
585585 var jobs = [];
586 - // Flag indicating that requests should be suspended
587 - var suspended = true;
588586 // Flag inidicating that document ready has occured
589587 var ready = false;
590588 // Marker element for adding dynamic styles
@@ -988,88 +986,85 @@
989987 }
990988 // Clean up the queue
991989 queue = [];
992 - // After document ready, handle the batch
993 - if ( !suspended && batch.length ) {
994 - // Always order modules alphabetically to help reduce cache
995 - // misses for otherwise identical content
996 - batch.sort();
997 - // Build a list of request parameters
998 - var base = {
999 - 'skin': mw.config.get( 'skin' ),
1000 - 'lang': mw.config.get( 'wgUserLanguage' ),
1001 - 'debug': mw.config.get( 'debug' )
1002 - };
1003 - // Extend request parameters with a list of modules in the batch
1004 - var requests = [];
1005 - // Split into groups
1006 - var groups = {};
1007 - for ( var b = 0; b < batch.length; b++ ) {
1008 - var group = registry[batch[b]].group;
1009 - if ( !( group in groups ) ) {
1010 - groups[group] = [];
 990+ // Always order modules alphabetically to help reduce cache
 991+ // misses for otherwise identical content
 992+ batch.sort();
 993+ // Build a list of request parameters
 994+ var base = {
 995+ 'skin': mw.config.get( 'skin' ),
 996+ 'lang': mw.config.get( 'wgUserLanguage' ),
 997+ 'debug': mw.config.get( 'debug' )
 998+ };
 999+ // Extend request parameters with a list of modules in the batch
 1000+ var requests = [];
 1001+ // Split into groups
 1002+ var groups = {};
 1003+ for ( var b = 0; b < batch.length; b++ ) {
 1004+ var group = registry[batch[b]].group;
 1005+ if ( !( group in groups ) ) {
 1006+ groups[group] = [];
 1007+ }
 1008+ groups[group][groups[group].length] = batch[b];
 1009+ }
 1010+ for ( var group in groups ) {
 1011+ // Calculate the highest timestamp
 1012+ var version = 0;
 1013+ for ( var g = 0; g < groups[group].length; g++ ) {
 1014+ if ( registry[groups[group][g]].version > version ) {
 1015+ version = registry[groups[group][g]].version;
10111016 }
1012 - groups[group][groups[group].length] = batch[b];
10131017 }
1014 - for ( var group in groups ) {
1015 - // Calculate the highest timestamp
1016 - var version = 0;
1017 - for ( var g = 0; g < groups[group].length; g++ ) {
1018 - if ( registry[groups[group][g]].version > version ) {
1019 - version = registry[groups[group][g]].version;
1020 - }
 1018+ var reqBase = $.extend( { 'version': formatVersionNumber( version ) }, base );
 1019+ var reqBaseLength = $.param( reqBase ).length;
 1020+ var reqs = [];
 1021+ var limit = mw.config.get( 'wgResourceLoaderMaxQueryLength', -1 );
 1022+ // We may need to split up the request to honor the query string length limit
 1023+ // So build it piece by piece
 1024+ var l = reqBaseLength + 9; // '&modules='.length == 9
 1025+ var r = 0;
 1026+ reqs[0] = {}; // { prefix: [ suffixes ] }
 1027+ for ( var i = 0; i < groups[group].length; i++ ) {
 1028+ // Determine how many bytes this module would add to the query string
 1029+ var lastDotIndex = groups[group][i].lastIndexOf( '.' );
 1030+ // Note that these substr() calls work even if lastDotIndex == -1
 1031+ var prefix = groups[group][i].substr( 0, lastDotIndex );
 1032+ var suffix = groups[group][i].substr( lastDotIndex + 1 );
 1033+ var bytesAdded = prefix in reqs[r] ?
 1034+ suffix.length + 3 : // '%2C'.length == 3
 1035+ groups[group][i].length + 3; // '%7C'.length == 3
 1036+
 1037+ // If the request would become too long, create a new one,
 1038+ // but don't create empty requests
 1039+ if ( limit > 0 && reqs[r] != {} && l + bytesAdded > limit ) {
 1040+ // This request would become too long, create a new one
 1041+ r++;
 1042+ reqs[r] = {};
 1043+ l = reqBaseLength + 9;
10211044 }
1022 - var reqBase = $.extend( { 'version': formatVersionNumber( version ) }, base );
1023 - var reqBaseLength = $.param( reqBase ).length;
1024 - var reqs = [];
1025 - var limit = mw.config.get( 'wgResourceLoaderMaxQueryLength', -1 );
1026 - // We may need to split up the request to honor the query string length limit
1027 - // So build it piece by piece
1028 - var l = reqBaseLength + 9; // '&modules='.length == 9
1029 - var r = 0;
1030 - reqs[0] = {}; // { prefix: [ suffixes ] }
1031 - for ( var i = 0; i < groups[group].length; i++ ) {
1032 - // Determine how many bytes this module would add to the query string
1033 - var lastDotIndex = groups[group][i].lastIndexOf( '.' );
1034 - // Note that these substr() calls work even if lastDotIndex == -1
1035 - var prefix = groups[group][i].substr( 0, lastDotIndex );
1036 - var suffix = groups[group][i].substr( lastDotIndex + 1 );
1037 - var bytesAdded = prefix in reqs[r] ?
1038 - suffix.length + 3 : // '%2C'.length == 3
1039 - groups[group][i].length + 3; // '%7C'.length == 3
1040 -
1041 - // If the request would become too long, create a new one,
1042 - // but don't create empty requests
1043 - if ( limit > 0 && reqs[r] != {} && l + bytesAdded > limit ) {
1044 - // This request would become too long, create a new one
1045 - r++;
1046 - reqs[r] = {};
1047 - l = reqBaseLength + 9;
1048 - }
1049 - if ( !( prefix in reqs[r] ) ) {
1050 - reqs[r][prefix] = [];
1051 - }
1052 - reqs[r][prefix].push( suffix );
1053 - l += bytesAdded;
 1045+ if ( !( prefix in reqs[r] ) ) {
 1046+ reqs[r][prefix] = [];
10541047 }
1055 - for ( var r = 0; r < reqs.length; r++ ) {
1056 - requests[requests.length] = $.extend(
1057 - { 'modules': buildModulesString( reqs[r] ) }, reqBase
1058 - );
1059 - }
 1048+ reqs[r][prefix].push( suffix );
 1049+ l += bytesAdded;
10601050 }
1061 - // Clear the batch - this MUST happen before we append the
1062 - // script element to the body or it's possible that the script
1063 - // will be locally cached, instantly load, and work the batch
1064 - // again, all before we've cleared it causing each request to
1065 - // include modules which are already loaded
1066 - batch = [];
1067 - // Asynchronously append a script tag to the end of the body
1068 - for ( var r = 0; r < requests.length; r++ ) {
1069 - requests[r] = sortQuery( requests[r] );
1070 - var src = mw.config.get( 'wgLoadScript' ) + '?' + $.param( requests[r] );
1071 - addScript( src );
 1051+ for ( var r = 0; r < reqs.length; r++ ) {
 1052+ requests[requests.length] = $.extend(
 1053+ { 'modules': buildModulesString( reqs[r] ) }, reqBase
 1054+ );
10721055 }
10731056 }
 1057+ // Clear the batch - this MUST happen before we append the
 1058+ // script element to the body or it's possible that the script
 1059+ // will be locally cached, instantly load, and work the batch
 1060+ // again, all before we've cleared it causing each request to
 1061+ // include modules which are already loaded
 1062+ batch = [];
 1063+ // Asynchronously append a script tag to the end of the body
 1064+ for ( var r = 0; r < requests.length; r++ ) {
 1065+ requests[r] = sortQuery( requests[r] );
 1066+ var src = mw.config.get( 'wgLoadScript' ) + '?' + $.param( requests[r] );
 1067+ addScript( src );
 1068+ }
10741069 };
10751070
10761071 /**
@@ -1261,14 +1256,6 @@
12621257 };
12631258
12641259 /**
1265 - * Flushes the request queue and begin executing load requests on demand
1266 - */
1267 - this.go = function() {
1268 - suspended = false;
1269 - mw.loader.work();
1270 - };
1271 -
1272 - /**
12731260 * Changes the state of a module
12741261 *
12751262 * @param module string module name or object of module name/state pairs

Sign-offs

UserFlagDate
Krinkleinspected07:37, 15 May 2011

Follow-up revisions

RevisionCommit summaryAuthorDate
r88136Fixes regression in r88125 - if batch is empty we should bail earlytparscal09:10, 15 May 2011
r88790Fix r88125: forgot to remove another call to mw.loader.go()catrope14:16, 25 May 2011
r88802Removing the last occurrences/mentions of mw.loader.go...krinkle17:18, 25 May 2011

Comments

#Comment by Krinkle (talk | contribs)   07:37, 15 May 2011
+				groups[group][groups[group].length] = batch[b];

Not confusing at all :D. Awesome line.

-			if ( !suspended && batch.length ) {

Did you intend to remove the batch.length check ?

Status & tagging log