jenkins-bot has submitted this change and it was merged.

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


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

This reverts commit 482ad8d9fb2e8273cefc4a5a557604b093944c8b.

Bug: T146099
Change-Id: Ic31463313b5a6d9720f0a5e036bb7200d3340021
---
M resources/src/mediawiki/mediawiki.js
1 file changed, 25 insertions(+), 53 deletions(-)

Approvals:
  Krinkle: Looks good to me, approved
  Ori.livneh: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/resources/src/mediawiki/mediawiki.js 
b/resources/src/mediawiki/mediawiki.js
index db5a4fb..78c674c 100644
--- a/resources/src/mediawiki/mediawiki.js
+++ b/resources/src/mediawiki/mediawiki.js
@@ -1195,7 +1195,7 @@
                                        // Force jQuery behaviour to be for 
crossDomain. Otherwise jQuery would use
                                        // XHR for a same domain request 
instead of <script>, which changes the request
                                        // headers (potentially missing a cache 
hit), and reduces caching in general
-                                       // since browsers cache XHR much less 
(if at all). And XHR means we retrieve
+                                       // since browsers cache XHR much less 
(if at all). And XHR means we retreive
                                        // text, so we'd need to $.globalEval, 
which then messes up line numbers.
                                        crossDomain: true,
                                        cache: true
@@ -1667,34 +1667,6 @@
                                }
                        }
 
-                       /**
-                        * Evaluate a batch of load.php responses retrieved 
from mw.loader.store.
-                        *
-                        * @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 batchEval( implementations, cb ) {
-                               if ( !implementations.length ) {
-                                       return;
-                               }
-                               mw.requestIdleCallback( function iterate( 
deadline ) {
-                                       while ( implementations[ 0 ] && 
deadline.timeRemaining() > 5 ) {
-                                               try {
-                                                       $.globalEval( 
implementations.shift() );
-                                               } catch ( err ) {
-                                                       cb( err );
-                                                       return;
-                                               }
-                                       }
-                                       if ( implementations[ 0 ] ) {
-                                               mw.requestIdleCallback( iterate 
);
-                                       }
-                               } );
-                       }
-
                        /* Public Members */
                        return {
                                /**
@@ -1719,7 +1691,7 @@
                                 * @protected
                                 */
                                work: function () {
-                                       var q, batch, implementations, 
sourceModules;
+                                       var q, batch, concatSource, origBatch;
 
                                        batch = [];
 
@@ -1736,50 +1708,50 @@
                                                }
                                        }
 
-                                       // Now that the queue has been 
processed into a batch, clear the queue.
-                                       // This MUST happen before we initiate 
any eval or network request. Otherwise,
-                                       // it is possible for a cached script 
to instantly trigger the same work queue
-                                       // again; all before we've cleared it 
causing each request to include modules
-                                       // which are already loaded.
-                                       queue = [];
-
-                                       if ( !batch.length ) {
-                                               return;
-                                       }
-
                                        mw.loader.store.init();
                                        if ( mw.loader.store.enabled ) {
-                                               implementations = [];
-                                               sourceModules = [];
+                                               concatSource = [];
+                                               origBatch = batch;
                                                batch = $.grep( batch, function 
( module ) {
-                                                       var implementation = 
mw.loader.store.get( module );
-                                                       if ( implementation ) {
-                                                               
implementations.push( implementation );
-                                                               
sourceModules.push( module );
+                                                       var source = 
mw.loader.store.get( module );
+                                                       if ( source ) {
+                                                               
concatSource.push( source );
                                                                return false;
                                                        }
                                                        return true;
                                                } );
-                                               batchEval( implementations, 
function ( err ) {
+                                               try {
+                                                       $.globalEval( 
concatSource.join( ';' ) );
+                                               } catch ( 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
                                                        // modules' implement() 
succeeded while the ones after the error will
                                                        // never run and leave 
their modules in the 'loading' state forever.
+
                                                        // Since this is an 
error not caused by an individual module but by
                                                        // 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' } );
-
-                                                       // Re-add the failed 
ones that are still pending back to the batch
-                                                       var failed = $.grep( 
sourceModules, function ( module ) {
+                                                       origBatch = $.grep( 
origBatch, function ( module ) {
                                                                return 
registry[ module ].state === 'loading';
                                                        } );
-                                                       batchRequest( failed );
-                                               } );
+                                                       batch = batch.concat( 
origBatch );
+                                               }
                                        }
 
+                                       // Now that the queue has been 
processed into a batch, clear up the queue.
+                                       // This MUST happen before we initiate 
any network request. Else it's possible
+                                       // that a script will be locally 
cached, instantly load, and work the queue
+                                       // again; all before we've cleared it 
causing each request to include modules
+                                       // which are already loaded.
+                                       queue = [];
+
                                        batchRequest( batch );
                                },
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ic31463313b5a6d9720f0a5e036bb7200d3340021
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: wmf/1.28.0-wmf.18
Gerrit-Owner: Krinkle <krinklem...@gmail.com>
Gerrit-Reviewer: Jack Phoenix <j...@countervandalism.net>
Gerrit-Reviewer: Krinkle <krinklem...@gmail.com>
Gerrit-Reviewer: Ori.livneh <o...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to