mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-13 09:40:34 +08:00
Perf: improve domainlist performance
This commit is contained in:
parent
683b743f44
commit
16ce1d0443
@ -1,13 +1,9 @@
|
||||
import { fastNormalizeDomain, fastNormalizeDomainWithoutWww } from '../normalize-domain';
|
||||
import { processLine } from '../process-line';
|
||||
import { onBlackFound } from './shared';
|
||||
import { fetchAssets } from '../fetch-assets';
|
||||
import type { Span } from '../../trace';
|
||||
|
||||
function domainListLineCb(l: string, set: string[], meta: string, normalizeDomain = fastNormalizeDomain) {
|
||||
const line = processLine(l);
|
||||
if (!line) return;
|
||||
|
||||
function domainListLineCb(line: string, set: string[], meta: string, normalizeDomain = fastNormalizeDomain) {
|
||||
const domain = normalizeDomain(line);
|
||||
if (!domain) return;
|
||||
|
||||
@ -24,31 +20,6 @@ function domainListLineCbIncludeAllSubdomain(line: string, set: string[], meta:
|
||||
|
||||
set.push('.' + domain);
|
||||
}
|
||||
|
||||
export function processDomainLists(
|
||||
span: Span,
|
||||
domainListsUrl: string, mirrors: string[] | null, includeAllSubDomain = false
|
||||
) {
|
||||
const lineCb = includeAllSubDomain ? domainListLineCbIncludeAllSubdomain : domainListLineCb;
|
||||
|
||||
return span.traceChildAsync(`process domainlist: ${domainListsUrl}`, async (span) => {
|
||||
const filterRules = await span.traceChildAsync('download', () => fetchAssets(
|
||||
domainListsUrl,
|
||||
mirrors,
|
||||
true
|
||||
));
|
||||
const domainSets: string[] = [];
|
||||
|
||||
span.traceChildSync('parse domain list', () => {
|
||||
for (let i = 0, len = filterRules.length; i < len; i++) {
|
||||
lineCb(filterRules[i], domainSets, domainListsUrl, fastNormalizeDomainWithoutWww);
|
||||
}
|
||||
});
|
||||
|
||||
return domainSets;
|
||||
});
|
||||
}
|
||||
|
||||
export function processDomainListsWithPreload(
|
||||
domainListsUrl: string, mirrors: string[] | null,
|
||||
includeAllSubDomain = false
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user