Krinkle has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/322219

Change subject: Revert "Revert "resourceloader: Make cache-eval in 
mw.loader.work asynchronous""
......................................................................

Revert "Revert "resourceloader: Make cache-eval in mw.loader.work asynchronous""

Undo the temp revert for observing metrics for T146510.

This reverts commit 29f0b2319f34651d6f494567450af4132f554bb0.

Change-Id: I67e972dc4dd8149d97a407f08887db6a008705cb
---
M resources/src/mediawiki/mediawiki.js
1 file changed, 33 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/19/322219/1

diff --git a/resources/src/mediawiki/mediawiki.js 
b/resources/src/mediawiki/mediawiki.js
index 9bb0ec8..d525813 100644
--- a/resources/src/mediawiki/mediawiki.js
+++ b/resources/src/mediawiki/mediawiki.js
@@ -1666,6 +1666,26 @@
                        }
 
                        /**
+                        * @private
+                        * @param {string[]} implementations Array containing 
pieces of JavaScript code in the
+                        *  form of calls to mw.loader#implement().
+                        * @param {Function} cb Callback in case of failure
+                        * @param {Error} cb.err
+                        */
+                       function asyncEval( implementations, cb ) {
+                               if ( !implementations.length ) {
+                                       return;
+                               }
+                               mw.requestIdleCallback( function () {
+                                       try {
+                                               $.globalEval( 
implementations.join( ';' ) );
+                                       } catch ( err ) {
+                                               cb( err );
+                                       }
+                               } );
+                       }
+
+                       /**
                         * Make a versioned key for a specific module.
                         *
                         * @private
@@ -1718,7 +1738,7 @@
                                 * @protected
                                 */
                                work: function () {
-                                       var q, batch, concatSource, origBatch;
+                                       var q, batch, implementations, 
sourceModules;
 
                                        batch = [];
 
@@ -1748,19 +1768,18 @@
 
                                        mw.loader.store.init();
                                        if ( mw.loader.store.enabled ) {
-                                               concatSource = [];
-                                               origBatch = batch;
+                                               implementations = [];
+                                               sourceModules = [];
                                                batch = $.grep( batch, function 
( module ) {
-                                                       var source = 
mw.loader.store.get( module );
-                                                       if ( source ) {
-                                                               
concatSource.push( source );
+                                                       var implementation = 
mw.loader.store.get( module );
+                                                       if ( implementation ) {
+                                                               
implementations.push( implementation );
+                                                               
sourceModules.push( module );
                                                                return false;
                                                        }
                                                        return true;
                                                } );
-                                               try {
-                                                       $.globalEval( 
concatSource.join( ';' ) );
-                                               } catch ( err ) {
+                                               asyncEval( implementations, 
function ( err ) {
                                                        // Not good, the cached 
mw.loader.implement calls failed! This should
                                                        // never happen, 
barring ResourceLoader bugs, browser bugs and PEBKACs.
                                                        // Depending on how 
corrupt the string is, it is likely that some
@@ -1772,16 +1791,14 @@
                                                        // something that 
infected the implement call itself, don't take any
                                                        // risks and clear 
everything in this cache.
                                                        mw.loader.store.clear();
-                                                       // Re-add the ones 
still pending back to the batch and let the server
-                                                       // repopulate these 
modules to the cache.
-                                                       // This means that at 
most one module will be useless (the one that had
-                                                       // the error) instead 
of all of them.
+
                                                        mw.track( 
'resourceloader.exception', { exception: err, source: 'store-eval' } );
-                                                       origBatch = $.grep( 
origBatch, function ( module ) {
+                                                       // Re-add the failed 
ones that are still pending back to the batch
+                                                       var failed = $.grep( 
sourceModules, function ( module ) {
                                                                return 
registry[ module ].state === 'loading';
                                                        } );
-                                                       batch = batch.concat( 
origBatch );
-                                               }
+                                                       batchRequest( failed );
+                                               } );
                                        }
 
                                        batchRequest( batch );

-- 
To view, visit https://gerrit.wikimedia.org/r/322219
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I67e972dc4dd8149d97a407f08887db6a008705cb
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: wmf/1.29.0-wmf.3
Gerrit-Owner: Krinkle <krinklem...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to