Perf: preload/hoist more promises, make ts happy

This commit is contained in:
SukkaW
2024-01-14 23:47:22 +08:00
parent 6daf8e3bb4
commit a3e1a85c70
7 changed files with 80 additions and 80 deletions

View File

@@ -24,6 +24,7 @@ const BLACKLIST = [
export const getMicrosoftCdnRulesetPromise = createMemoizedPromise(async () => {
const set = await traceAsync('fetch accelerated-domains.china.conf', async () => {
// First trie is to find the microsoft domains that matches probe domains
const trie = createTrie();
for await (const line of await fetchRemoteTextByLine('https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/accelerated-domains.china.conf')) {
if (line.startsWith('server=/') && line.endsWith('/114.114.114.114')) {
@@ -34,6 +35,7 @@ export const getMicrosoftCdnRulesetPromise = createMemoizedPromise(async () => {
return new Set(PROBE_DOMAINS.flatMap(domain => trie.find(domain, false)));
});
// Second trie is to remove blacklisted domains
const trie2 = createTrie(set);
const black = BLACKLIST.flatMap(domain => trie2.find(domain, true));
for (let i = 0, len = black.length; i < len; i++) {