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

Change subject: Generate less timeouts on pages that make a lot of API requests
......................................................................


Generate less timeouts on pages that make a lot of API requests

 * Increase maxSockets for API requests. The default in node is 5 per host.
   Parsing pages with lots of templates makes many concurrent connections
   that end up timing out. Bumping this up shaves at least a minute off
   that large test case in the bug report:

   fr/Liste_des_premiers_préfets_français_(1800-1815)

 * Cache and coalesce ImageInfoRequests.

Bug: 55585
Change-Id: Ia025a90a52b45c0816983d1b7b34fc074b6b4c4f
---
M js/lib/ext.core.LinkHandler.js
M js/lib/mediawiki.ApiRequest.js
2 files changed, 16 insertions(+), 2 deletions(-)

Approvals:
  GWicke: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/js/lib/ext.core.LinkHandler.js b/js/lib/ext.core.LinkHandler.js
index 51bf2ad..a410c1a 100644
--- a/js/lib/ext.core.LinkHandler.js
+++ b/js/lib/ext.core.LinkHandler.js
@@ -1169,9 +1169,18 @@
                }
        }
 
-       var infoRequest = new ImageInfoRequest( env, filename, constraints );
+       var queueKey = filename + JSON.stringify( constraints );
 
-       infoRequest.on( 'src', handleResponse.bind( null, linkTitle ) );
+       if ( queueKey in env.pageCache ) {
+               handleResponse( linkTitle, null, env.pageCache[ queueKey ] );
+               return;
+       }
+
+       if ( !(queueKey in env.requestQueue) ) {
+               env.requestQueue[ queueKey ] = new ImageInfoRequest( env, 
filename, constraints );
+       }
+
+       env.requestQueue[ queueKey ].once( 'src', handleResponse.bind( null, 
linkTitle ) );
        cb( { async: true } );
 };
 
diff --git a/js/lib/mediawiki.ApiRequest.js b/js/lib/mediawiki.ApiRequest.js
index dd3d5b3..2c5e95d 100644
--- a/js/lib/mediawiki.ApiRequest.js
+++ b/js/lib/mediawiki.ApiRequest.js
@@ -2,6 +2,9 @@
 
 require('./core-upgrade.js');
 
+// many concurrent connections to the same host
+require('http').globalAgent.maxSockets = 15;
+
 var request = require('request'),
        $ = require( './fakejquery' ),
        qs = require('querystring'),
@@ -682,6 +685,7 @@
 function ImageInfoRequest( env, filename, dims ) {
        ApiRequest.call( this, env, null );
        this.env = env;
+       this.queueKey = filename + JSON.stringify( dims );
 
        var ix,
                conf = env.conf.wiki,
@@ -770,6 +774,7 @@
 
                data.query.pages = newpages;
                data.query.imgns = this.ns;
+               this.env.pageCache[ this.queueKey ] = data.query;
                this._processListeners( null, data.query );
        } else if ( data && data.error ) {
                if ( data.error.code === 'readapidenied' ) {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia025a90a52b45c0816983d1b7b34fc074b6b4c4f
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Parsoid
Gerrit-Branch: master
Gerrit-Owner: Arlolra <[email protected]>
Gerrit-Reviewer: GWicke <[email protected]>
Gerrit-Reviewer: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to