Only build reference search index when it's been changed

Using the same tricks as ve.ce.MWReferenceListNode... Like listening to list
node updates, which will probably catch unrelated changes? I'm not sure about
this.

Bug: 68890
Change-Id: Id9443c9574063933bc8fb35d09ab8b80b69bcd44
This commit is contained in:
Alex Monk 2014-08-01 21:39:17 +01:00
parent c66bd9f9f2
commit 79d953f6b0

View file

@ -26,6 +26,7 @@ ve.ui.MWReferenceSearchWidget = function VeUiMWReferenceSearchWidget( config ) {
// Properties
this.index = [];
this.indexEmpty = true;
this.built = false;
// Initialization
this.$element.addClass( 've-ui-mwReferenceSearchWidget' );
@ -93,6 +94,8 @@ ve.ui.MWReferenceSearchWidget.prototype.setInternalList = function ( internalLis
}
this.internalList = internalList;
this.internalList.connect( this, { 'update': 'onInternalListUpdate' } );
this.internalList.getListNode().connect( this, { 'update': 'onListNodeUpdate' } );
groupNames = ve.getObjectKeys( groups );
for ( i = 0, iLen = groupNames.length; i < iLen; i++ ) {
@ -107,14 +110,43 @@ ve.ui.MWReferenceSearchWidget.prototype.setInternalList = function ( internalLis
}
};
/**
* Handle the updating of the InternalList object.
*
* This will occur after a document transaction.
*
* @method
* @param {string[]} groupsChanged A list of groups which have changed in this transaction
*/
ve.ui.MWReferenceSearchWidget.prototype.onInternalListUpdate = function ( groupsChanged ) {
for ( var i = 0, len = groupsChanged.length; i < len; i++ ) {
if ( groupsChanged[i].indexOf( 'mwReference/' ) === 0 ) {
this.built = false;
break;
}
}
};
/**
* Handle the updating of the InternalListNode.
*
* This will occur after changes to any InternalItemNode.
*
* @method
*/
ve.ui.MWReferenceSearchWidget.prototype.onListNodeUpdate = function () {
this.built = false;
};
/**
* Build a searchable index of references.
*
* @method
*/
ve.ui.MWReferenceSearchWidget.prototype.buildIndex = function () {
// FIXME: For performance, this should only build the index if (a) there's no existing index, or
// (b) there is, but it was built against a different version of the internalList. (Bug: 68890)
if ( this.built ) {
return;
}
var i, iLen, j, jLen, ref, group, groupName, groupNames, view, text, firstNodes, indexOrder,
refGroup, refNode, matches, name, citation,
@ -172,6 +204,8 @@ ve.ui.MWReferenceSearchWidget.prototype.buildIndex = function () {
// Re-populate
this.onQueryChange();
this.built = true;
};
/**