Santhosh has uploaded a new change for review. https://gerrit.wikimedia.org/r/263542
Change subject: Templates: Cache the template data requests ...................................................................... Templates: Cache the template data requests The getTargetTemplate method in Templates module was not optimized to reuse the template data we recieved already. This causes too many requests for template information. Testplan: For example, watch the network requests while translating https://en.wikipedia.org/wiki/Electronic_cigarette to some language. Without this patch, you will see hundreds of duplicate requests. With this patch, you should see only a few unique requests Bug: T123301 Change-Id: Ife2fee28d0ab20dc3c0effedccd3e7ab0a39ee9a --- M modules/tools/ext.cx.tools.template.js 1 file changed, 14 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation refs/changes/42/263542/1 diff --git a/modules/tools/ext.cx.tools.template.js b/modules/tools/ext.cx.tools.template.js index 5192994..b20445c 100644 --- a/modules/tools/ext.cx.tools.template.js +++ b/modules/tools/ext.cx.tools.template.js @@ -10,6 +10,8 @@ ( function ( $, mw ) { 'use strict'; + var cachedTemplates = {}; + /** * TemplateTool encapsulates the handling of templates in translation. * @@ -180,11 +182,16 @@ * @return {number} return.done.data The page id */ TemplateTool.prototype.getTargetTemplate = function () { + var api, request; + + if ( cachedTemplates[ this.templateTitle ] ) { + return cachedTemplates[ this.templateTitle ].promise(); + } // TODO: Avoid direct access to globals - var api = mw.cx.siteMapper.getApi( mw.cx.targetLanguage ); + api = mw.cx.siteMapper.getApi( mw.cx.targetLanguage ); // Note that we use canonical namespace 'Template' for title. - return api.get( { + request = api.get( { action: 'query', titles: 'Template:' + this.templateTitle, redirects: true, @@ -199,9 +206,12 @@ if ( pageId === '-1' ) { return $.Deferred().reject().promise(); } - return response.query; - } ).promise(); + } ); + + cachedTemplates[ this.templateTitle ] = request; + + return request.promise(); }; /** -- To view, visit https://gerrit.wikimedia.org/r/263542 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ife2fee28d0ab20dc3c0effedccd3e7ab0a39ee9a Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ContentTranslation Gerrit-Branch: master Gerrit-Owner: Santhosh <santhosh.thottin...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits