mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-13 09:40:34 +08:00
Perf/Refactor: processHosts now returns string[]
This commit is contained in:
parent
aa3cb9e586
commit
6b0151be29
@ -36,7 +36,7 @@ export const buildRejectDomainSet = task(import.meta.path, async (span) => {
|
|||||||
let shouldStop = false;
|
let shouldStop = false;
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
// Parse from remote hosts & domain lists
|
// Parse from remote hosts & domain lists
|
||||||
...HOSTS.map(entry => processHosts(childSpan, entry[0], entry[1], entry[2], entry[3]).then(hosts => SetAdd(domainSets, hosts))),
|
...HOSTS.map(entry => processHosts(childSpan, entry[0], entry[1], entry[2], entry[3]).then(setAddFromArrayCurried(domainSets))),
|
||||||
|
|
||||||
...DOMAIN_LISTS.map(entry => processDomainLists(childSpan, entry[0], entry[1], entry[2]).then(setAddFromArrayCurried(domainSets))),
|
...DOMAIN_LISTS.map(entry => processDomainLists(childSpan, entry[0], entry[1], entry[2]).then(setAddFromArrayCurried(domainSets))),
|
||||||
|
|
||||||
|
|||||||
@ -21,6 +21,5 @@ export const normalizeDomain = (domain: string) => {
|
|||||||
h = h.slice(sliceStart, sliceEnd);
|
h = h.slice(sliceStart, sliceEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (h) return h;
|
return h || null;
|
||||||
return null;
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -47,7 +47,7 @@ export function processDomainLists(span: Span, domainListsUrl: string, includeAl
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
const hostsLineCb = (l: string, set: Set<string>, includeAllSubDomain: boolean, meta: string) => {
|
const hostsLineCb = (l: string, set: string[], includeAllSubDomain: boolean, meta: string) => {
|
||||||
const line = processLine(l);
|
const line = processLine(l);
|
||||||
if (!line) {
|
if (!line) {
|
||||||
return;
|
return;
|
||||||
@ -66,15 +66,15 @@ const hostsLineCb = (l: string, set: Set<string>, includeAllSubDomain: boolean,
|
|||||||
foundDebugDomain = true;
|
foundDebugDomain = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
set.add(includeAllSubDomain ? `.${domain}` : domain);
|
set.push(includeAllSubDomain ? `.${domain}` : domain);
|
||||||
};
|
};
|
||||||
|
|
||||||
export function processHosts(span: Span, hostsUrl: string, mirrors: string[] | null, includeAllSubDomain = false, ttl: number | null = null) {
|
export function processHosts(span: Span, hostsUrl: string, mirrors: string[] | null, includeAllSubDomain = false, ttl: number | null = null) {
|
||||||
const domainSets = new Set<string>();
|
|
||||||
|
|
||||||
return span.traceChild(`processhosts: ${hostsUrl}`).traceAsyncFn((childSpan) => fsFetchCache.apply(
|
return span.traceChild(`processhosts: ${hostsUrl}`).traceAsyncFn((childSpan) => fsFetchCache.apply(
|
||||||
hostsUrl,
|
hostsUrl,
|
||||||
async () => {
|
async () => {
|
||||||
|
const domainSets: string[] = [];
|
||||||
|
|
||||||
if (mirrors == null || mirrors.length === 0) {
|
if (mirrors == null || mirrors.length === 0) {
|
||||||
for await (const l of await fetchRemoteTextByLine(hostsUrl)) {
|
for await (const l of await fetchRemoteTextByLine(hostsUrl)) {
|
||||||
hostsLineCb(l, domainSets, includeAllSubDomain, hostsUrl);
|
hostsLineCb(l, domainSets, includeAllSubDomain, hostsUrl);
|
||||||
@ -91,15 +91,13 @@ export function processHosts(span: Span, hostsUrl: string, mirrors: string[] | n
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(picocolors.gray('[process hosts]'), picocolors.gray(hostsUrl), picocolors.gray(domainSets.size));
|
|
||||||
|
|
||||||
return domainSets;
|
return domainSets;
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ttl,
|
ttl,
|
||||||
temporaryBypass,
|
temporaryBypass,
|
||||||
serializer: serializeSet,
|
serializer: serializeArray,
|
||||||
deserializer: deserializeSet
|
deserializer: deserializeArray
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user