mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 02:23:58 +00:00
MWReferenceSearchWidget buildIndex optimisations
* Each item builds an MWReferenceModel which creates a document slice clone. This is very expensive and we only use the model for getting basic attributes, so defer the evaluation of the document. * $.show is expensive and, in this case, unnecessary. Change-Id: I99abc4c1b17f05559a9cae68b15121a8be6d23fb
This commit is contained in:
parent
365453f2b3
commit
d4cd816b6f
|
@ -23,6 +23,7 @@ ve.dm.MWReferenceModel = function VeDmMWReferenceModel() {
|
|||
this.listIndex = null;
|
||||
this.group = '';
|
||||
this.doc = null;
|
||||
this.deferDoc = null;
|
||||
};
|
||||
|
||||
/* Inheritance */
|
||||
|
@ -47,7 +48,10 @@ ve.dm.MWReferenceModel.static.newFromReferenceNode = function ( node ) {
|
|||
ref.setListGroup( attr.listGroup );
|
||||
ref.setListIndex( attr.listIndex );
|
||||
ref.setGroup( attr.refGroup );
|
||||
ref.setDocument( doc.cloneFromRange( internalList.getItemNode( attr.listIndex ).getRange() ) );
|
||||
ref.deferDoc = function () {
|
||||
// cloneFromRange is very expensive, so lazy evaluate it
|
||||
return doc.cloneFromRange( internalList.getItemNode( attr.listIndex ).getRange() );
|
||||
};
|
||||
|
||||
return ref;
|
||||
};
|
||||
|
@ -149,7 +153,7 @@ ve.dm.MWReferenceModel.prototype.updateInternalItem = function ( surfaceModel )
|
|||
itemNodeRange = internalList.getItemNode( this.listIndex ).getRange();
|
||||
surfaceModel.change( ve.dm.Transaction.newFromRemoval( doc, itemNodeRange, true ) );
|
||||
surfaceModel.change(
|
||||
ve.dm.Transaction.newFromDocumentInsertion( doc, itemNodeRange.start, this.doc )
|
||||
ve.dm.Transaction.newFromDocumentInsertion( doc, itemNodeRange.start, this.getDocument() )
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -219,6 +223,9 @@ ve.dm.MWReferenceModel.prototype.getGroup = function () {
|
|||
*/
|
||||
ve.dm.MWReferenceModel.prototype.getDocument = function () {
|
||||
if ( !this.doc ) {
|
||||
if ( this.deferDoc ) {
|
||||
this.doc = this.deferDoc();
|
||||
} else {
|
||||
this.doc = new ve.dm.Document( [
|
||||
{ 'type': 'paragraph', 'internal': { 'generated': 'wrapper' } },
|
||||
{ 'type': '/paragraph' },
|
||||
|
@ -226,6 +233,7 @@ ve.dm.MWReferenceModel.prototype.getDocument = function () {
|
|||
{ 'type': '/internalList' }
|
||||
] );
|
||||
}
|
||||
}
|
||||
return this.doc;
|
||||
};
|
||||
|
||||
|
|
|
@ -131,7 +131,7 @@ ve.ui.MWReferenceSearchWidget.prototype.buildIndex = function ( internalList ) {
|
|||
view.$element.find( 'a[href]' ).each( extractAttrs );
|
||||
|
||||
this.index.push( {
|
||||
'$element': view.$element.clone().show(),
|
||||
'$element': view.$element.clone(),
|
||||
'text': text,
|
||||
'reference': ref,
|
||||
'citation': citation,
|
||||
|
|
Loading…
Reference in a new issue