cache pays

This commit is contained in:
Christophe Robillard 2020-11-30 10:53:55 +01:00 committed by LeSim (Rebase PR Action)
parent a8ed9ef172
commit ddd50993a5

View file

@ -33,8 +33,7 @@ function buildOptions() {
async function defaultQueryFn(scope, term) {
if (scope == 'pays') {
const pays = await fetch('/pays.json').then((response) => response.json());
return matchSorter(pays, term, { keys: ['nom'] });
return matchSorter(await getPays(), term, { keys: ['nom'] });
}
const url = buildURL(scope, term);
@ -43,3 +42,11 @@ async function defaultQueryFn(scope, term) {
promise.cancel = () => controller && controller.abort();
return promise;
}
let paysCache;
async function getPays() {
if (!paysCache) {
paysCache = await fetch('/pays.json').then((response) => response.json());
}
return paysCache;
}