Perf: optimize filter debugger

This commit is contained in:
SukkaW 2024-12-29 12:48:29 +08:00
parent 1df5ede2ea
commit b63aae756e
2 changed files with 27 additions and 23 deletions

View File

@ -10,10 +10,29 @@ import { createAhoCorasick as createKeywordFilter } from 'foxts/ahocorasick';
import { looseTldtsOpt } from '../constants/loose-tldts-opt'; import { looseTldtsOpt } from '../constants/loose-tldts-opt';
import { identity } from 'foxts/identity'; import { identity } from 'foxts/identity';
import { DEBUG_DOMAIN_TO_FIND } from '../constants/reject-data-source'; import { DEBUG_DOMAIN_TO_FIND } from '../constants/reject-data-source';
import { noop } from 'foxts/noop';
let foundDebugDomain = false; let foundDebugDomain = false;
const temporaryBypass = typeof DEBUG_DOMAIN_TO_FIND === 'string'; const temporaryBypass = typeof DEBUG_DOMAIN_TO_FIND === 'string';
const onBlackFound = DEBUG_DOMAIN_TO_FIND
? (line: string, meta: string) => {
if (line.includes(DEBUG_DOMAIN_TO_FIND!)) {
console.warn(picocolors.red(meta), '(black)', line.replaceAll(DEBUG_DOMAIN_TO_FIND!, picocolors.bold(DEBUG_DOMAIN_TO_FIND)));
foundDebugDomain = true;
}
}
: noop;
const onWhiteFound = DEBUG_DOMAIN_TO_FIND
? (line: string, meta: string) => {
if (line.includes(DEBUG_DOMAIN_TO_FIND!)) {
console.warn(picocolors.red(meta), '(white)', line.replaceAll(DEBUG_DOMAIN_TO_FIND!, picocolors.bold(DEBUG_DOMAIN_TO_FIND)));
foundDebugDomain = true;
}
}
: noop;
function domainListLineCb(l: string, set: string[], includeAllSubDomain: boolean, meta: string) { function domainListLineCb(l: string, set: string[], includeAllSubDomain: boolean, meta: string) {
let line = processLine(l); let line = processLine(l);
if (!line) return; if (!line) return;
@ -32,10 +51,7 @@ function domainListLineCb(l: string, set: string[], includeAllSubDomain: boolean
return; return;
} }
if (DEBUG_DOMAIN_TO_FIND && line.includes(DEBUG_DOMAIN_TO_FIND)) { onBlackFound(domain, meta);
console.warn(picocolors.red(meta), '(black)', line.replaceAll(DEBUG_DOMAIN_TO_FIND, picocolors.bold(DEBUG_DOMAIN_TO_FIND)));
foundDebugDomain = true;
}
set.push(includeAllSubDomain ? `.${line}` : line); set.push(includeAllSubDomain ? `.${line}` : line);
} }
@ -84,10 +100,8 @@ function hostsLineCb(l: string, set: string[], includeAllSubDomain: boolean, met
if (!domain) { if (!domain) {
return; return;
} }
if (DEBUG_DOMAIN_TO_FIND && domain.includes(DEBUG_DOMAIN_TO_FIND)) {
console.warn(picocolors.red(meta), '(black)', domain.replaceAll(DEBUG_DOMAIN_TO_FIND, picocolors.bold(DEBUG_DOMAIN_TO_FIND))); onBlackFound(domain, meta);
foundDebugDomain = true;
}
set.push(includeAllSubDomain ? `.${domain}` : domain); set.push(includeAllSubDomain ? `.${domain}` : domain);
} }
@ -169,15 +183,10 @@ export async function processFilterRules(
const hostname = result[0]; const hostname = result[0];
if (DEBUG_DOMAIN_TO_FIND && hostname.includes(DEBUG_DOMAIN_TO_FIND)) { if (flag === ParseType.WhiteIncludeSubdomain || flag === ParseType.WhiteAbsolute) {
console.warn( onWhiteFound(hostname, filterRulesUrl);
picocolors.red(filterRulesUrl), } else {
flag === ParseType.WhiteIncludeSubdomain || flag === ParseType.WhiteAbsolute onBlackFound(hostname, filterRulesUrl);
? '(white)'
: '(black)',
hostname.replaceAll(DEBUG_DOMAIN_TO_FIND, picocolors.bold(DEBUG_DOMAIN_TO_FIND))
);
foundDebugDomain = true;
} }
switch (flag) { switch (flag) {

View File

@ -27,12 +27,7 @@ export class DomainsetOutput extends RuleOutput<string[]> {
this.$surge.push(subdomain ? '.' + domain : domain); this.$surge.push(subdomain ? '.' + domain : domain);
this.$clash.push(subdomain ? `+.${domain}` : domain); this.$clash.push(subdomain ? `+.${domain}` : domain);
(subdomain ? this.$singbox_domains_suffixes : this.$singbox_domains).push(domain); (subdomain ? this.$singbox_domains_suffixes : this.$singbox_domains).push(domain);
this.$adguardhome.push(subdomain ? `||${domain}^` : `|${domain}^`);
if (subdomain) {
this.$adguardhome.push(`||${domain}^`);
} else {
this.$adguardhome.push(`|${domain}^`);
}
}, true); }, true);
return this.$surge; return this.$surge;