jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/336494 )
Change subject: Cache generated content request when inserting templates ...................................................................... Cache generated content request when inserting templates We request the generated content of a template to determine if it will be block or inline. This is the same request as the view makes later to show the rendering, so we should cache this repsonse. Bug: T156698 Change-Id: I0ffd36ccd0aa821aa44d99328f2e3a2abc23dc0f --- M modules/ve-mw/dm/models/ve.dm.MWTransclusionModel.js 1 file changed, 16 insertions(+), 5 deletions(-) Approvals: Bartosz Dziewoński: Looks good to me, approved jenkins-bot: Verified Jforrester: Looks good to me, but someone else must approve diff --git a/modules/ve-mw/dm/models/ve.dm.MWTransclusionModel.js b/modules/ve-mw/dm/models/ve.dm.MWTransclusionModel.js index a2b4f52..b5f0288 100644 --- a/modules/ve-mw/dm/models/ve.dm.MWTransclusionModel.js +++ b/modules/ve-mw/dm/models/ve.dm.MWTransclusionModel.js @@ -62,10 +62,11 @@ ve.dm.MWTransclusionModel.prototype.insertTransclusionNode = function ( surfaceFragment, forceType ) { var model = this, deferred = $.Deferred(), - nodeClass = ve.dm.MWTransclusionNode; + baseNodeClass = ve.dm.MWTransclusionNode; - function insertNode( isInline ) { - var type = isInline ? nodeClass.static.inlineType : nodeClass.static.blockType, + function insertNode( isInline, generatedContents ) { + var hash, store, nodeClass, + type = isInline ? baseNodeClass.static.inlineType : baseNodeClass.static.blockType, range = surfaceFragment.getSelection().getCoveringRange(), data = [ { @@ -76,6 +77,15 @@ }, { type: '/' + type } ]; + + // If we just fetched the generated contents, put them in the store + // so we don't do a duplicate API call later. + if ( generatedContents ) { + nodeClass = ve.dm.modelRegistry.lookup( type ); + store = surfaceFragment.getDocument().getStore(); + hash = OO.getHash( [ nodeClass.static.getHashObjectForRendering( data[ 0 ] ), undefined ] ); + store.index( generatedContents, hash ); + } if ( range.isCollapsed() ) { surfaceFragment.insertContent( data ); @@ -97,7 +107,7 @@ action: 'visualeditor', paction: 'parsefragment', page: mw.config.get( 'wgRelevantPageName' ), - wikitext: nodeClass.static.getWikitext( this.getPlainObject() ), + wikitext: baseNodeClass.static.getWikitext( this.getPlainObject() ), pst: 1 } ) .then( function ( response ) { @@ -107,7 +117,8 @@ contentNodes = $.parseHTML( response.visualeditor.content, surfaceFragment.getDocument().getHtmlDocument() ) || []; contentNodes = ve.ce.MWTransclusionNode.static.filterRendering( contentNodes ); insertNode( - nodeClass.static.isHybridInline( contentNodes, ve.dm.converter ) + baseNodeClass.static.isHybridInline( contentNodes, ve.dm.converter ), + contentNodes ); } else { // Request failed - just assume inline -- To view, visit https://gerrit.wikimedia.org/r/336494 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I0ffd36ccd0aa821aa44d99328f2e3a2abc23dc0f Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/VisualEditor Gerrit-Branch: master Gerrit-Owner: Esanders <esand...@wikimedia.org> Gerrit-Reviewer: Bartosz Dziewoński <matma....@gmail.com> Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org> Gerrit-Reviewer: Krinkle <krinklem...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits