Merge "mw.loader.store: do one eval per batch, rather than one per module"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 29 Oct 2013 23:55:34 +0000 (23:55 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 29 Oct 2013 23:55:34 +0000 (23:55 +0000)
1  2 
resources/mediawiki/mediawiki.js

@@@ -21,7 -21,6 +21,7 @@@ var mw = ( function ( $, undefined ) 
         * fine. No need for optimization here, which would only result in losing logs.
         *
         * @private
 +       * @method log_
         * @param {string} msg text for the log entry.
         * @param {Error} [e]
         */
                }
        };
  
 +      /**
 +       * @class mw
 +       */
        return {
                /* Public Members */
  
                                 */
                                work: function () {
                                        var     reqBase, splits, maxQueryLength, q, b, bSource, bGroup, bSourceGroup,
-                                               source, group, g, i, modules, maxVersion, sourceLoadScript,
+                                               source, concatSource, group, g, i, modules, maxVersion, sourceLoadScript,
                                                currReqBase, currReqBaseLength, moduleMap, l,
                                                lastDotIndex, prefix, suffix, bytesAdded, async;
  
  
                                        mw.loader.store.init();
                                        if ( mw.loader.store.enabled ) {
+                                               concatSource = [];
                                                batch = $.grep( batch, function ( module ) {
                                                        var source = mw.loader.store.get( module );
                                                        if ( source ) {
-                                                               $.globalEval( source );
-                                                               return false; // Don't fetch
+                                                               concatSource.push( source );
+                                                               return false;
                                                        }
-                                                       return true; // Fetch
+                                                       return true;
                                                } );
+                                               $.globalEval( concatSource.join( ';' ) );
                                        }
  
                                        // Early exit if there's nothing to load...
                                 * @param {Function|Array} script Function with module code or Array of URLs to
                                 *  be used as the src attribute of a new `<script>` tag.
                                 * @param {Object} style Should follow one of the following patterns:
 +                               *
                                 *     { "css": [css, ..] }
                                 *     { "url": { <media>: [url, ..] } }
 +                               *
                                 * And for backwards compatibility (needs to be supported forever due to caching):
 +                               *
                                 *     { <media>: css }
                                 *     { <media>: [url, ..] }
                                 *
                                 * The reason css strings are not concatenated anymore is bug 31676. We now check
                                 * whether it's safe to extend the stylesheet (see #canExpandStylesheetWith).
                                 *
 -                               * @param {Object} msgs List of key/value pairs to be added to {@link mw#messages}.
 +                               * @param {Object} msgs List of key/value pairs to be added to mw#messages.
                                 */
                                implement: function ( module, script, style, msgs ) {
                                        // Validate input