attempt at making generation faster on weak remote machine
This commit is contained in:
parent
46a3a4f528
commit
fc8f6e3066
52
generate.js
52
generate.js
@ -723,32 +723,38 @@ const processRecords = async () => {
|
|||||||
await promiseMe(callback => fs.writeFile(targetFile, stateHtml, callback));
|
await promiseMe(callback => fs.writeFile(targetFile, stateHtml, callback));
|
||||||
console.log(`wrote to ${targetFile} in ${Date.now() - start}ms`);
|
console.log(`wrote to ${targetFile} in ${Date.now() - start}ms`);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
for (const stateData of countryData.states) {
|
|
||||||
if (!stateData.name || !stateData.counties || !stateData.counties.length) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
await Promise.all(stateData.counties.map(async (countyData) => {
|
|
||||||
countyData.population = countyData.population || 0;
|
|
||||||
|
|
||||||
const start = Date.now();
|
|
||||||
const targetFile = path.join(
|
|
||||||
publicDir,
|
|
||||||
'countries',
|
|
||||||
`${countryData.safeName}-${stateData.safeName}-${countyData.safeName}.html`,
|
|
||||||
);
|
|
||||||
const countyHtml = countyFn({
|
|
||||||
data: countyData,
|
|
||||||
$title: `${countyData.name}, ${countyData.state}, ${countyData.country}`,
|
|
||||||
lastUpdate,
|
|
||||||
});
|
|
||||||
await promiseMe(callback => fs.writeFile(targetFile, countyHtml, callback));
|
|
||||||
console.log(`wrote to ${targetFile} in ${Date.now() - start}ms`);
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
for (const countryData of countryArr) {
|
||||||
|
if (!countryData.states) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const stateData of countryData.states) {
|
||||||
|
if (!stateData.name || !stateData.counties || !stateData.counties.length) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (const countyData of stateData.counties) {
|
||||||
|
countyData.population = countyData.population || 0;
|
||||||
|
|
||||||
|
const start = Date.now();
|
||||||
|
const targetFile = path.join(
|
||||||
|
publicDir,
|
||||||
|
'countries',
|
||||||
|
`${countryData.safeName}-${stateData.safeName}-${countyData.safeName}.html`,
|
||||||
|
);
|
||||||
|
const countyHtml = countyFn({
|
||||||
|
data: countyData,
|
||||||
|
$title: `${countyData.name}, ${countyData.state}, ${countyData.country}`,
|
||||||
|
lastUpdate,
|
||||||
|
});
|
||||||
|
await promiseMe(callback => fs.writeFile(targetFile, countyHtml, callback));
|
||||||
|
console.log(`wrote to ${targetFile} in ${Date.now() - start}ms`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
console.log(`finished in ${((Date.now() - globalStart) / 1000).toFixed(2)}s`);
|
console.log(`finished in ${((Date.now() - globalStart) / 1000).toFixed(2)}s`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user