From 79d953f6b016ea503de277278658779d5258853f Mon Sep 17 00:00:00 2001 From: Alex Monk Date: Fri, 1 Aug 2014 21:39:17 +0100 Subject: [PATCH] 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 --- .../widgets/ve.ui.MWReferenceSearchWidget.js | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/modules/ve-mw/ui/widgets/ve.ui.MWReferenceSearchWidget.js b/modules/ve-mw/ui/widgets/ve.ui.MWReferenceSearchWidget.js index 3c5f617b65..7921eb9dbd 100644 --- a/modules/ve-mw/ui/widgets/ve.ui.MWReferenceSearchWidget.js +++ b/modules/ve-mw/ui/widgets/ve.ui.MWReferenceSearchWidget.js @@ -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; }; /**