2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-07 12:02:53 +08:00

FIX: makes mini-tag-chooser search more efficient

This commit is contained in:
Joffrey JAFFEUX 2018-02-15 15:01:19 +01:00 committed by GitHub
parent 585fc26f8e
commit 2cf40096d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,7 +3,7 @@ import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from 'discourse/lib/ajax-error'; import { popupAjaxError } from 'discourse/lib/ajax-error';
import { default as computed } from "ember-addons/ember-computed-decorators"; import { default as computed } from "ember-addons/ember-computed-decorators";
import renderTag from "discourse/lib/render-tag"; import renderTag from "discourse/lib/render-tag";
const { get, isEmpty, isPresent, run } = Ember; const { get, isEmpty, isPresent, run, makeArray } = Ember;
export default ComboBox.extend({ export default ComboBox.extend({
allowContentReplacement: true, allowContentReplacement: true,
@ -18,6 +18,20 @@ export default ComboBox.extend({
caretUpIcon: Ember.computed.alias("caretIcon"), caretUpIcon: Ember.computed.alias("caretIcon"),
caretDownIcon: 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") @computed("limitReached", "maximumSelectionSize")
maxContentRow(limitReached, count) { maxContentRow(limitReached, count) {
if (limitReached) { if (limitReached) {
@ -43,23 +57,9 @@ export default ComboBox.extend({
return false; 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") @computed("tags")
computedTags(tags) { computedTags(tags) {
return Ember.makeArray(tags); return makeArray(tags);
}, },
validateCreate(term) { validateCreate(term) {
@ -146,7 +146,7 @@ export default ComboBox.extend({
@computed("tags.[]", "filter") @computed("tags.[]", "filter")
collectionHeader(tags, filter) { collectionHeader(tags, filter) {
if (!Ember.isEmpty(tags)) { if (!isEmpty(tags)) {
let output = ""; let output = "";
if (tags.length >= 20) { if (tags.length >= 20) {
@ -186,39 +186,38 @@ export default ComboBox.extend({
delete tags[tags.indexOf(tag)]; delete tags[tags.indexOf(tag)];
this.set("tags", tags.filter(t => t)); this.set("tags", tags.filter(t => t));
this.set("content", []); 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() { 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) { onFilter(filter) {
filter = isEmpty(filter) ? null : 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) { onSelect(tag) {
if (isEmpty(this.get("computedTags"))) { if (isEmpty(this.get("computedTags"))) {
this.set("tags", Ember.makeArray(tag)); this.set("tags", makeArray(tag));
} else { } else {
this.set("tags", this.get("computedTags").concat(tag)); this.set("tags", this.get("computedTags").concat(tag));
} }
this.set("content", []); 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) { _searchTags(query) {
this.startLoading(); this.startLoading();
const selectedTags = Ember.makeArray(this.get("computedTags")).filter(t => t);
const self = this; const self = this;
const selectedTags = makeArray(this.get("computedTags")).filter(t => t);
const sortTags = this.siteSettings.tags_sort_alphabetically; const sortTags = this.siteSettings.tags_sort_alphabetically;
const data = { const data = {
q: query, q: query,
limit: this.siteSettings.max_tag_search_results, limit: this.siteSettings.max_tag_search_results,