mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Perf: improve build speed
This commit is contained in:
@@ -9,6 +9,7 @@ import { readFileIntoProcessedArray } from './lib/fetch-text-by-line';
|
||||
|
||||
import { DomainsetOutput } from './lib/create-file';
|
||||
import { OUTPUT_SURGE_DIR } from './constants/dir';
|
||||
import { createMemoizedPromise } from './lib/memo-promise';
|
||||
|
||||
const KEYWORDS = [
|
||||
'Hong Kong',
|
||||
@@ -183,6 +184,8 @@ async function querySpeedtestApi(keyword: string): Promise<Array<string | null>>
|
||||
}
|
||||
}
|
||||
|
||||
const getSpeedtestHostsGroupsPromise = createMemoizedPromise(() => Promise.all(KEYWORDS.flatMap(querySpeedtestApi)));
|
||||
|
||||
export const buildSpeedtestDomainSet = task(require.main === module, __filename)(async (span) => {
|
||||
const output = new DomainsetOutput(span, 'speedtest')
|
||||
.withTitle('Sukka\'s Ruleset - Speedtest Domains')
|
||||
@@ -194,14 +197,9 @@ export const buildSpeedtestDomainSet = task(require.main === module, __filename)
|
||||
.addFromDomainset(PREDEFINE_DOMAINS)
|
||||
.addFromDomainset(await readFileIntoProcessedArray(path.resolve(OUTPUT_SURGE_DIR, 'domainset/speedtest.conf')));
|
||||
|
||||
await Promise.all(KEYWORDS.map((keyword) => span.traceChildAsync(
|
||||
`fetch speedtest endpoints: ${keyword}`,
|
||||
() => querySpeedtestApi(keyword)
|
||||
).then(hostnameGroup => hostnameGroup.forEach(hostname => {
|
||||
if (hostname) {
|
||||
output.addDomain(hostname);
|
||||
}
|
||||
}))));
|
||||
const hostnameGroup = await span.traceChildPromise('get speedtest hosts groups', getSpeedtestHostsGroupsPromise());
|
||||
|
||||
hostnameGroup.forEach(hostname => output.bulkAddDomain(hostname));
|
||||
|
||||
return output.write();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user