mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 09:10:35 +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;
|
||||
await Promise.all([
|
||||
// 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))),
|
||||
|
||||
|
||||
@ -21,6 +21,5 @@ export const normalizeDomain = (domain: string) => {
|
||||
h = h.slice(sliceStart, sliceEnd);
|
||||
}
|
||||
|
||||
if (h) return h;
|
||||
return null;
|
||||
return h || 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);
|
||||
if (!line) {
|
||||
return;
|
||||
@ -66,15 +66,15 @@ const hostsLineCb = (l: string, set: Set<string>, includeAllSubDomain: boolean,
|
||||
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) {
|
||||
const domainSets = new Set<string>();
|
||||
|
||||
return span.traceChild(`processhosts: ${hostsUrl}`).traceAsyncFn((childSpan) => fsFetchCache.apply(
|
||||
hostsUrl,
|
||||
async () => {
|
||||
const domainSets: string[] = [];
|
||||
|
||||
if (mirrors == null || mirrors.length === 0) {
|
||||
for await (const l of await fetchRemoteTextByLine(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;
|
||||
},
|
||||
{
|
||||
ttl,
|
||||
temporaryBypass,
|
||||
serializer: serializeSet,
|
||||
deserializer: deserializeSet
|
||||
serializer: serializeArray,
|
||||
deserializer: deserializeArray
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user