mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 01:00:34 +08:00
Refactor: adjust domainset
This commit is contained in:
parent
274c2453e2
commit
6e9d2181eb
@ -137,14 +137,6 @@ export const buildRejectDomainSet = task(require.main === module, __filename)(as
|
||||
}
|
||||
});
|
||||
|
||||
span.traceChildSync(
|
||||
'build domain map for sort & collect stat',
|
||||
() => {
|
||||
rejectOutput.calcDomainMap();
|
||||
rejectExtraOutput.calcDomainMap();
|
||||
}
|
||||
);
|
||||
|
||||
// Create reject stats
|
||||
const rejectDomainsStats: string[] = span
|
||||
.traceChild('create reject stats')
|
||||
|
||||
@ -3,7 +3,6 @@ import createKeywordFilter from '../aho-corasick';
|
||||
import { buildParseDomainMap, sortDomains } from '../stable-sort-domain';
|
||||
import { RuleOutput } from './base';
|
||||
import type { SingboxSourceFormat } from '../singbox';
|
||||
import { nullthrow } from 'foxact/nullthrow';
|
||||
|
||||
type Preprocessed = string[];
|
||||
|
||||
@ -15,29 +14,24 @@ export class DomainsetOutput extends RuleOutput<Preprocessed> {
|
||||
|
||||
const results: string[] = [];
|
||||
|
||||
const dumped = this.domainTrie.dump();
|
||||
|
||||
for (let i = 0, len = dumped.length; i < len; i++) {
|
||||
const domain = dumped[i];
|
||||
if (!kwfilter(domain)) {
|
||||
results.push(domain);
|
||||
this.domainTrie.dump((domain) => {
|
||||
if (kwfilter(domain)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
results.push(domain);
|
||||
});
|
||||
|
||||
if (!this.apexDomainMap || !this.subDomainMap) {
|
||||
const { domainMap, subdomainMap } = buildParseDomainMap(results);
|
||||
this.apexDomainMap = domainMap;
|
||||
this.subDomainMap = subdomainMap;
|
||||
}
|
||||
const sorted = sortDomains(results, this.apexDomainMap, this.subDomainMap);
|
||||
sorted.push('this_ruleset_is_made_by_sukkaw.ruleset.skk.moe');
|
||||
|
||||
return sorted;
|
||||
}
|
||||
|
||||
calcDomainMap() {
|
||||
if (!this.apexDomainMap || !this.subDomainMap) {
|
||||
const { domainMap, subdomainMap } = buildParseDomainMap(this.$preprocessed);
|
||||
this.apexDomainMap = domainMap;
|
||||
this.subDomainMap = subdomainMap;
|
||||
}
|
||||
}
|
||||
|
||||
surge(): string[] {
|
||||
return this.$preprocessed;
|
||||
}
|
||||
@ -72,17 +66,18 @@ export class DomainsetOutput extends RuleOutput<Preprocessed> {
|
||||
invariant(this.$preprocessed, 'Non dumped yet');
|
||||
invariant(this.apexDomainMap, 'Missing apex domain map');
|
||||
|
||||
return Array.from(
|
||||
nullthrow(this.$preprocessed, 'Non dumped yet')
|
||||
.reduce<Map<string, number>>((acc, cur) => {
|
||||
return Array.from(this.$preprocessed
|
||||
.reduce<Map<string, number>>(
|
||||
(acc, cur) => {
|
||||
const suffix = this.apexDomainMap!.get(cur);
|
||||
if (suffix) {
|
||||
acc.set(suffix, (acc.get(suffix) ?? 0) + 1);
|
||||
}
|
||||
return acc;
|
||||
}, new Map())
|
||||
.entries()
|
||||
)
|
||||
},
|
||||
new Map()
|
||||
)
|
||||
.entries())
|
||||
.filter(a => a[1] > 9)
|
||||
.sort(
|
||||
(a, b) => (b[1] - a[1]) || a[0].localeCompare(b[0])
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user