Skip to content

A platform for community discussion. Free, open, simple.

FIX: makes mini-tag-chooser search more efficient

Joffrey JAFFEUX2cf40096d11b
diff --git a/app/assets/javascripts/select-kit/components/mini-tag-chooser.js.es6 b/app/assets/javascripts/select-kit/components/mini-tag-chooser.js.es6
index f623043370d..d28f7a1caae 100644
--- a/app/assets/javascripts/select-kit/components/mini-tag-chooser.js.es6
+++ b/app/assets/javascripts/select-kit/components/mini-tag-chooser.js.es6
@@ -3,7 +3,7 @@ import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from 'discourse/lib/ajax-error';
import { default as computed } from "ember-addons/ember-computed-decorators";
import renderTag from "discourse/lib/render-tag";
-const { get, isEmpty, isPresent, run } = Ember;
+const { get, isEmpty, isPresent, run, makeArray } = Ember;
export default ComboBox.extend({
allowContentReplacement: true,
@@ -18,6 +18,20 @@ export default ComboBox.extend({
caretUpIcon: Ember.computed.alias("caretIcon"),
caretDownIcon: Ember.computed.alias("caretIcon"),
+ init() {
+ this._super();
+
+ this.set("termMatchesForbidden", false);
+
+ this.set("templateForRow", (rowComponent) => {
+ const tag = rowComponent.get("computedContent");
+ return renderTag(get(tag, "value"), {
+ count: get(tag, "originalContent.count"),
+ noHref: true
+ });
+ });
+ },
+
@computed("limitReached", "maximumSelectionSize")
maxContentRow(limitReached, count) {
if (limitReached) {
@@ -43,23 +57,9 @@ export default ComboBox.extend({
return false;
},
- init() {
- this._super();
-
- this.set("termMatchesForbidden", false);
-
- this.set("templateForRow", (rowComponent) => {
- const tag = rowComponent.get("computedContent");
- return renderTag(get(tag, "value"), {
- count: get(tag, "originalContent.count"),
- noHref: true
- });
- });
- },
-
@computed("tags")
computedTags(tags) {
- return Ember.makeArray(tags);
+ return makeArray(tags);
},
validateCreate(term) {
@@ -146,7 +146,7 @@ export default ComboBox.extend({
@computed("tags.[]", "filter")
collectionHeader(tags, filter) {
- if (!Ember.isEmpty(tags)) {
+ if (!isEmpty(tags)) {
let output = "";
if (tags.length >= 20) {
@@ -186,39 +186,38 @@ export default ComboBox.extend({
delete tags[tags.indexOf(tag)];
this.set("tags", tags.filter(t => t));
this.set("content", []);
- this.set("searchDebounce", run.debounce(this, this._searchTags, 200));
+ this.set("searchDebounce", run.debounce(this, this._searchTags, this.get("filter"), 250));
},
onExpand() {
- this.set("searchDebounce", run.debounce(this, this._searchTags, 200));
+ if (isEmpty(this.get("content"))) {
+ this.set("searchDebounce", run.debounce(this, this._searchTags, this.get("filter"), 250));
+ }
},
onFilter(filter) {
filter = isEmpty(filter) ? null : filter;
- this.set("searchDebounce", run.debounce(this, this._searchTags, filter, 200));
+ this.set("searchDebounce", run.debounce(this, this._searchTags, filter, 250));
},
onSelect(tag) {
if (isEmpty(this.get("computedTags"))) {
- this.set("tags", Ember.makeArray(tag));
+ this.set("tags", makeArray(tag));
} else {
this.set("tags", this.get("computedTags").concat(tag));
}
this.set("content", []);
- this.set("searchDebounce", run.debounce(this, this._searchTags, 200));
+ this.set("searchDebounce", run.debounce(this, this._searchTags, this.get("filter"), 250));
}
},
_searchTags(query) {
this.startLoading();
- const selectedTags = Ember.makeArray(this.get("computedTags")).filter(t => t);
-
const self = this;
-
+ const selectedTags = makeArray(this.get("computedTags")).filter(t => t);
const sortTags = this.siteSettings.tags_sort_alphabetically;
-
const data = {
q: query,
limit: this.siteSettings.max_tag_search_results,