Perf: optimize sort domains & preload promise

This commit is contained in:
SukkaW
2024-01-14 23:29:29 +08:00
parent eaf993deca
commit 6daf8e3bb4
5 changed files with 48 additions and 31 deletions

View File

@@ -16,8 +16,9 @@ export const parseWithoutDetectIp = parse2;
let gothillGetDomainCache: ReturnType<typeof createCache> | null = null;
export const createCachedGorhillGetDomain = (gorhill: PublicSuffixList) => {
gothillGetDomainCache ??= createCache('cached-gorhill-get-domain', true);
return (domain: string) => {
gothillGetDomainCache ??= createCache('cached-gorhill-get-domain', true);
return gothillGetDomainCache.sync(domain, () => gorhill.getDomain(domain[0] === '.' ? domain.slice(1) : domain));
// we do know gothillGetDomainCache exists here
return gothillGetDomainCache!.sync(domain, () => gorhill.getDomain(domain[0] === '.' ? domain.slice(1) : domain));
};
};