From 2185a5e806a062842f0fe29f11910156fba6c535 Mon Sep 17 00:00:00 2001 From: SukkaW Date: Thu, 5 Sep 2024 23:40:58 +0800 Subject: [PATCH] Chore: update reject stats builder --- Build/build-reject-domainset.ts | 39 +++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/Build/build-reject-domainset.ts b/Build/build-reject-domainset.ts index e9a2fd8a..d7bdfad1 100644 --- a/Build/build-reject-domainset.ts +++ b/Build/build-reject-domainset.ts @@ -20,6 +20,7 @@ import { getPhishingDomains } from './lib/get-phishing-domains'; import { setAddFromArray, setAddFromArrayCurried } from './lib/set-add-from-array'; import { output } from './lib/misc'; +import { appendArrayInPlace } from './lib/append-array-in-place'; const getRejectSukkaConfPromise = readFileIntoProcessedArray(path.resolve(__dirname, '../Source/domainset/reject_sukka.conf')); @@ -161,18 +162,15 @@ export const buildRejectDomainSet = task(require.main === module, __filename)(as ); // Create reject stats - const rejectDomainsStats: Array<[string, number]> = span + const rejectDomainsStats: string[] = span .traceChild('create reject stats') .traceSyncFn(() => { - const statMap = dudupedDominArray.reduce>((acc, cur) => { - const suffix = domainArrayMainDomainMap.get(cur); - if (suffix) { - acc.set(suffix, (acc.get(suffix) ?? 0) + 1); - } - return acc; - }, new Map()); - - return Array.from(statMap.entries()).filter(a => a[1] > 9).sort((a, b) => (b[1] - a[1]) || a[0].localeCompare(b[0])); + const results = []; + results.push('=== base ==='); + appendArrayInPlace(results, getStatMap(dudupedDominArray, domainArrayMainDomainMap)); + results.push('=== extra ==='); + appendArrayInPlace(results, getStatMap(dudupedDominArrayExtra, domainArrayMainDomainMap)); + return results; }); return Promise.all([ @@ -215,8 +213,27 @@ export const buildRejectDomainSet = task(require.main === module, __filename)(as ), compareAndWriteFile( span, - rejectDomainsStats.map(([domain, count]) => `${domain}${' '.repeat(100 - domain.length)}${count}`), + rejectDomainsStats, path.resolve(__dirname, '../Internal/reject-stats.txt') ) ]); }); + +function getStatMap(domains: string[], domainArrayMainDomainMap: Map): string[] { + return Array.from( + ( + domains.reduce>((acc, cur) => { + const suffix = domainArrayMainDomainMap.get(cur); + if (suffix) { + acc.set(suffix, (acc.get(suffix) ?? 0) + 1); + } + return acc; + }, new Map()) + ).entries() + ) + .filter(a => a[1] > 9) + .sort( + (a, b) => (b[1] - a[1]) || a[0].localeCompare(b[0]) + ) + .map(([domain, count]) => `${domain}${' '.repeat(100 - domain.length)}${count}`); +};