Feature #44194 ยป 0001-Cache-mention-autocomplete-responses-to-avoid-redund.patch
| app/assets/javascripts/application-legacy.js | ||
|---|---|---|
|
xhr.send();
|
||
|
}, 200);
|
||
|
const autocompleteSearchCache = {};
|
||
|
const latestAutocompleteSearchQuery = {};
|
||
|
const cachedAutocompleteSearch = function(url, text) {
|
||
|
const cache = autocompleteSearchCache[url];
|
||
|
if (!cache) {
|
||
|
return null;
|
||
|
}
|
||
|
if (text === cache.query) {
|
||
|
return cache.results;
|
||
|
}
|
||
|
if (cache.query && text.startsWith(cache.query) && cache.results.length === 0) {
|
||
|
return [];
|
||
|
}
|
||
|
return null;
|
||
|
}
|
||
|
const tribute = new Tribute({
|
||
|
collection: [
|
||
|
{
|
||
| ... | ... | |
|
},
|
||
|
values: function (text, cb) {
|
||
|
const url = getDataSource('users');
|
||
|
if (url) {
|
||
|
remoteSearch(url + encodeURIComponent(text), function (users) {
|
||
|
return cb(users);
|
||
|
});
|
||
|
if (!url) {
|
||
|
return cb([]);
|
||
|
}
|
||
|
const cachedUsers = cachedAutocompleteSearch(url, text);
|
||
|
if (cachedUsers !== null) {
|
||
|
return cb(cachedUsers);
|
||
|
}
|
||
|
latestAutocompleteSearchQuery[url] = text;
|
||
|
remoteSearch(url + encodeURIComponent(text), function (users) {
|
||
|
if (latestAutocompleteSearchQuery[url] !== text) {
|
||
|
return;
|
||
|
}
|
||
|
autocompleteSearchCache[url] = {
|
||
|
query: text,
|
||
|
results: users
|
||
|
};
|
||
|
return cb(users);
|
||
|
});
|
||
|
},
|
||
|
menuItemTemplate: function (user) {
|
||
|
return sanitizeHTML(user.original.name);
|
||