mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 01:00:34 +08:00
Perf: improve build speed
This commit is contained in:
parent
3c5499995b
commit
e347587e6c
@ -29,7 +29,7 @@ const getS3OSSDomainsPromise = (async (): Promise<string[]> => {
|
||||
(line.startsWith('s3-') || line.startsWith('s3.'))
|
||||
&& !line.includes('cn-')
|
||||
) {
|
||||
S3OSSDomains.add(line);
|
||||
S3OSSDomains.add('.' + line);
|
||||
}
|
||||
});
|
||||
trie.find('.scw.cloud').forEach((line: string) => {
|
||||
@ -37,14 +37,14 @@ const getS3OSSDomainsPromise = (async (): Promise<string[]> => {
|
||||
(line.startsWith('s3-') || line.startsWith('s3.'))
|
||||
&& !line.includes('cn-')
|
||||
) {
|
||||
S3OSSDomains.add(line);
|
||||
S3OSSDomains.add('.' + line);
|
||||
}
|
||||
});
|
||||
trie.find('sakurastorage.jp').forEach((line: string) => {
|
||||
if (
|
||||
(line.startsWith('s3-') || line.startsWith('s3.'))
|
||||
) {
|
||||
S3OSSDomains.add(line);
|
||||
S3OSSDomains.add('.' + line);
|
||||
}
|
||||
});
|
||||
|
||||
@ -66,7 +66,7 @@ export const buildCdnDownloadConf = task(require.main === module, __filename)(as
|
||||
]);
|
||||
|
||||
// Move S3 domains to download domain set, since S3 files may be large
|
||||
appendArrayInPlace(downloadDomainSet, S3OSSDomains.map(domain => `.${domain}`));
|
||||
appendArrayInPlace(downloadDomainSet, S3OSSDomains);
|
||||
appendArrayInPlace(downloadDomainSet, steamDomainSet);
|
||||
|
||||
// we have whitelisted the crashlytics domain, and we also want to put it in CDN policy
|
||||
|
||||
@ -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();
|
||||
});
|
||||
|
||||
@ -90,9 +90,13 @@ export abstract class RuleOutput<TPreprocessed = unknown> {
|
||||
return this;
|
||||
}
|
||||
|
||||
bulkAddDomain(domains: string[]) {
|
||||
bulkAddDomain(domains: Array<string | null>) {
|
||||
let d: string | null;
|
||||
for (let i = 0, len = domains.length; i < len; i++) {
|
||||
this.addDomain(domains[i]);
|
||||
d = domains[i];
|
||||
if (d !== null) {
|
||||
this.addDomain(d);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user