Skip to content

Commit

Permalink
Perf: reduce infra runtime costs
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Sep 14, 2023
1 parent 0a4c99a commit 28ac484
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Build/build-cdn-conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { runner } = require('./lib/trace-runner');
const fs = require('fs');
const { processLine } = require('./lib/process-line');

const publicSuffixPath = path.resolve(__dirname, '../node_modules/.cache/public_suffix-list_dat.txt');
const publicSuffixPath = path.resolve(__dirname, '../node_modules/.cache/public_suffix_list_dat.txt');

const buildCdnConf = async () => {
const trie = new Trie();
Expand Down
Empty file removed Build/build.js
Empty file.
2 changes: 1 addition & 1 deletion Build/download-previous-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const downloadPreviousBuild = async () => {

const downloadPublicSuffixList = async () => {
const publicSuffixDir = resolve(__dirname, '../node_modules/.cache');
const publicSuffixPath = join(publicSuffixDir, 'public_suffix-list_dat.txt');
const publicSuffixPath = join(publicSuffixDir, 'public_suffix_list_dat.txt');

console.log('Download public suffix list.');

Expand Down
78 changes: 78 additions & 0 deletions Build/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
const { downloadPreviousBuild, downloadPublicSuffixList } = require('./download-previous-build');
const { buildCommon } = require('./build-common');
const { buildAntiBogusDomain } = require('./build-anti-bogus-domain');
const { buildAppleCdn } = require('./build-apple-cdn');
const { buildCdnConf } = require('./build-cdn-conf');
const { buildPhishingDomainSet } = require('./build-phishing-domainset');
const { buildRejectDomainSet } = require('./build-reject-domainset');
const { buildTelegramCIDR } = require('./build-telegram-cidr');
const { buildChnCidr } = require('./build-chn-cidr');
const { buildSpeedtestDomainSet } = require('./build-speedtest-domainset');
const { buildInternalCDNDomains } = require('./build-internal-cdn-rules');
const { buildInternalReverseChnCIDR } = require('./build-internal-reverse-chn-cidr');
const { buildInternalChnDomains } = require('./build-internal-chn-domains');
const { buildDomesticRuleset } = require('./build-domestic-ruleset');
const { validate } = require('./validate-domainset');

const { buildPublicHtml } = require('./build-public');

(async () => {
// download-previous-build
const downloadPreviousBuildPromise = downloadPreviousBuild();
const downloadPublicSuffixListPromise = downloadPublicSuffixList();
// build:common
const buildCommonPromise = downloadPreviousBuildPromise.then(() => buildCommon());
// build:anti-bogus-domain
const buildAntiBogusDomainPromise = downloadPreviousBuildPromise.then(() => buildAntiBogusDomain());
// build:apple-cdn
const buildAppleCdnPromise = downloadPreviousBuildPromise.then(() => buildAppleCdn());
// build:cdn-conf
const buildCdnConfPromise = downloadPreviousBuildPromise.then(() => buildCdnConf());
// build:phishing-domainset
const buildPhilishingDomainsetPromise = downloadPreviousBuildPromise.then(() => buildPhishingDomainSet());
// build:reject-domainset
const buildRejectDomainSetPromise = Promise.all([
downloadPreviousBuildPromise,
downloadPublicSuffixListPromise
]).then(() => buildRejectDomainSet());
// build:telegram-cidr
const buildTelegramCIDRPromise = downloadPreviousBuildPromise.then(() => buildTelegramCIDR());
// build:chn-cidr
const buildChnCidrPromise = downloadPreviousBuildPromise.then(() => buildChnCidr());
// build:speedtest-domainset
const buildSpeedtestDomainSetPromise = downloadPreviousBuildPromise.then(() => buildSpeedtestDomainSet());
// build:internal-cdn-rules
const buildInternalCDNDomainsPromise = Promise.all([
buildCommonPromise,
buildCdnConfPromise
]).then(() => buildInternalCDNDomains());
// build:internal-reverse-chn-cidr
const buildInternalReverseChnCIDRPromise = buildInternalReverseChnCIDR();
// build:internal-chn-domains
const buildInternalChnDomainsPromise = buildInternalChnDomains();
// build:domestic-ruleset
const buildDomesticRulesetPromise = downloadPreviousBuildPromise.then(() => buildDomesticRuleset());

await Promise.all([
downloadPreviousBuildPromise,
downloadPublicSuffixListPromise,
buildCommonPromise,
buildAntiBogusDomainPromise,
buildAppleCdnPromise,
buildCdnConfPromise,
buildPhilishingDomainsetPromise,
buildRejectDomainSetPromise,
buildTelegramCIDRPromise,
buildChnCidrPromise,
buildSpeedtestDomainSetPromise,
buildInternalCDNDomainsPromise,
buildInternalReverseChnCIDRPromise,
buildInternalChnDomainsPromise,
buildDomesticRulesetPromise
]);

await Promise.all([
buildPublicHtml(),
validate()
]);
})();
3 changes: 2 additions & 1 deletion Build/lib/cached-tld-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ module.exports.parse = (domain) => {
return cache.sync(domain, () => tldts.parse(domain, sharedConfig));
};

const gothillGetDomainCache = createCache('cached-gorhill-get-domain', true);
let gothillGetDomainCache = null;
/**
* @param {import('gorhill-publicsuffixlist').default | null} gorhill
*/
module.exports.createCachedGorhillGetDomain = (gorhill) => {
gothillGetDomainCache ||= createCache('cached-gorhill-get-domain', true);
/**
* @param {string} domain
*/
Expand Down
2 changes: 1 addition & 1 deletion Build/lib/get-gorhill-publicsuffix.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { toASCII } = require('punycode/');
const fs = require('fs');
const path = require('path');

const publicSuffixPath = path.resolve(__dirname, '../../node_modules/.cache/public_suffix-list_dat.txt');
const publicSuffixPath = path.resolve(__dirname, '../../node_modules/.cache/public_suffix_list_dat.txt');
const getPublicSuffixListDat = () => {
if (fs.existsSync(publicSuffixPath)) {
return fs.promises.readFile(publicSuffixPath, 'utf-8');
Expand Down
21 changes: 2 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"private": true,
"description": "",
"scripts": {
"build": "wireit",
"build": "node ./Build/index.js",

"build:common": "wireit",
"download-previous-build": "wireit",
"build:anti-bogus-domain": "wireit",
Expand Down Expand Up @@ -124,24 +125,6 @@
"build:cdn-conf",
"build:common"
]
},
"build": {
"dependencies": [
"build:common",
"build:anti-bogus-domain",
"build:apple-cdn",
"build:cdn-conf",
"build:reject-domainset",
"build:telegram-cidr",
"build:chn-cidr",
"build:internal-cdn-rules",
"build:internal-reverse-chn-cidr",
"build:internal-chn-domains",
"build:speedtest-domainset",
"build:domestic-ruleset",
"build:public",
"validate:domainset"
]
}
},
"repository": {
Expand Down

0 comments on commit 28ac484

Please sign in to comment.