Skip to content

Commit 061639f

Browse files
author
Vladimir Kotal
authored
Merge pull request #1237 from tulinkry/project-picker-performance
improving performance of project picker filter
2 parents 60b97ab + b9fe3a5 commit 061639f

File tree

2 files changed

+53
-12
lines changed

2 files changed

+53
-12
lines changed

web/js/searchable-option-list-2.0.2.js

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
maxHeight: undefined,
143143
converter: undefined,
144144
asyncBatchSize: 300,
145+
searchTimeout: 300,
145146
maxShow: 0
146147
},
147148

@@ -454,7 +455,13 @@
454455
valueChanged = e.originalEvent.propertyName.toLowerCase()=='value';
455456
}
456457
if (valueChanged) {
457-
self._applySearchTermFilter();
458+
if ($(this).data('timeout')) {
459+
clearTimeout($(this).data('timeout'));
460+
}
461+
$(this).data('timeout', setTimeout(function () {
462+
self._applySearchTermFilter();
463+
}, self.config.searchTimeout))
464+
458465
}
459466
});
460467

@@ -586,30 +593,49 @@
586593
return;
587594
}
588595

589-
var self = this;
596+
var self = this,
597+
amountOfUnfilteredItems = dataArray.length
590598

591599
// reset keyboard navigation mode when applying new filter
592600
this._setKeyBoardNavigationMode(false);
593601

594-
$.each(dataArray, function (index, item) {
602+
/*
603+
* Modified 2016
604+
* recursion was very slow (however good lookin')
605+
*/
606+
for (var itemIndex = 0; itemIndex < dataArray.length; itemIndex++) {
607+
var item = dataArray[itemIndex];
595608
if (item.type === 'option') {
596609
var $element = item.displayElement,
597-
elementSearchableTerms = (item.label + ' ' + item.tooltip).trim().toLowerCase();
610+
elementSearchableTerms = (item.label + ' ' + item.tooltip).trim().toLowerCase();
598611

599612
if (elementSearchableTerms.indexOf(searchTerm) === -1) {
600613
$element.addClass('sol-filtered-search');
614+
amountOfUnfilteredItems--;
601615
}
602616
} else {
603-
self._findTerms(item.children, searchTerm);
604-
var amountOfUnfilteredChildren = item.displayElement.find('.sol-option:not(.sol-filtered-search)');
617+
var amountOfUnfilteredChildren = item.children.length
618+
for (var childrenIndex = 0; childrenIndex < item.children.length; childrenIndex++) {
619+
var child = item.children[childrenIndex];
620+
if (child.type === 'option') {
621+
var $element = child.displayElement,
622+
elementSearchableTerms = (child.label + ' ' + child.tooltip).trim().toLowerCase();
623+
624+
if (elementSearchableTerms.indexOf(searchTerm) === -1) {
625+
$element.addClass('sol-filtered-search');
626+
amountOfUnfilteredChildren--;
627+
}
628+
}
629+
}
605630

606-
if (amountOfUnfilteredChildren.length === 0) {
631+
if (amountOfUnfilteredChildren === 0) {
607632
item.displayElement.addClass('sol-filtered-search');
633+
amountOfUnfilteredItems--;
608634
}
609635
}
610-
});
636+
}
611637

612-
this._setNoResultsItemVisible(this.$selectionContainer.find('.sol-option:not(.sol-filtered-search)').length === 0);
638+
this._setNoResultsItemVisible(amountOfUnfilteredItems === 0);
613639
},
614640

615641
_initializeData: function () {
@@ -1146,7 +1172,7 @@
11461172
.prop('checked', true)
11471173
.trigger('change', true);
11481174

1149-
this.options.closeOnClick && this.close();
1175+
this.config.closeOnClick && this.close();
11501176

11511177
if ($.isFunction(this.config.events.onChange)) {
11521178
this.config.events.onChange.call(this, this, $changedInputs);
@@ -1168,7 +1194,7 @@
11681194
$closedInputs.prop('checked', true)
11691195
.trigger('change', true)
11701196

1171-
this.options.closeOnClick && this.close();
1197+
this.config.closeOnClick && this.close();
11721198

11731199
if ($.isFunction(this.config.events.onChange)) {
11741200
this.config.events.onChange.call(this, this, $openedInputs.add($closedInputs));

0 commit comments

Comments
 (0)