DEV: removes setTimeout and reduces timer in tests (#9701)

This commit is contained in:
Joffrey JAFFEUX 2020-05-08 16:46:24 +02:00 committed by GitHub
parent 646bee2efe
commit 350fe932ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 8 deletions

View File

@ -4,6 +4,7 @@ import Category from "discourse/models/category";
import { TAG_HASHTAG_POSTFIX } from "discourse/lib/tag-hashtags";
import { SEPARATOR } from "discourse/lib/category-hashtags";
import { Promise } from "rsvp";
import { later, cancel } from "@ember/runloop";
var cache = {};
var cacheTime;
@ -17,9 +18,12 @@ function updateCache(term, results) {
function searchTags(term, categories, limit) {
return new Promise(resolve => {
const clearPromise = setTimeout(() => {
resolve(CANCELLED_STATUS);
}, 5000);
const clearPromise = later(
() => {
resolve(CANCELLED_STATUS);
},
Ember.testing ? 25 : 5000
);
const debouncedSearch = discourseDebounce((q, cats, resultFunc) => {
oldSearch = $.ajax(Discourse.getURL("/tags/filter/search"), {
@ -55,7 +59,7 @@ function searchTags(term, categories, limit) {
}, 300);
debouncedSearch(term, categories, result => {
clearTimeout(clearPromise);
cancel(clearPromise);
resolve(updateCache(term, result));
});
});

View File

@ -3,6 +3,7 @@ import { CANCELLED_STATUS } from "discourse/lib/autocomplete";
import { userPath } from "discourse/lib/url";
import { emailValid } from "discourse/lib/utilities";
import { Promise } from "rsvp";
import { later, cancel } from "@ember/runloop";
var cache = {},
cacheKey,
@ -180,9 +181,12 @@ export default function userSearch(options) {
cacheKey = newCacheKey;
var clearPromise = setTimeout(function() {
resolve(CANCELLED_STATUS);
}, 5000);
const clearPromise = later(
() => {
resolve(CANCELLED_STATUS);
},
Ember.testing ? 25 : 5000
);
if (skipSearch(term, options.allowEmails)) {
resolve([]);
@ -199,7 +203,7 @@ export default function userSearch(options) {
allowedUsers,
groupMembersOf,
function(r) {
clearTimeout(clearPromise);
cancel(clearPromise);
resolve(organizeResults(r, options));
}
);