removed concurrency from generation script

This commit is contained in:
tmont 2020-07-23 12:42:03 -07:00
parent fc8f6e3066
commit 86db797765

View File

@ -696,7 +696,7 @@ const processRecords = async () => {
const stateFn = pug.compileFile(singleStateTmpl); const stateFn = pug.compileFile(singleStateTmpl);
const countyFn = pug.compileFile(singleCountyTmpl); const countyFn = pug.compileFile(singleCountyTmpl);
await Promise.all(countryArr.map(async (countryData) => { for (const countryData of countryArr) {
const start = Date.now(); const start = Date.now();
const targetFile = path.join(publicDir, 'countries', countryData.safeName + '.html'); const targetFile = path.join(publicDir, 'countries', countryData.safeName + '.html');
const countryHtml = countryFn({ const countryHtml = countryFn({
@ -704,29 +704,9 @@ const processRecords = async () => {
$title: countryData.name, $title: countryData.name,
lastUpdate, lastUpdate,
}); });
console.log(`writing to ${targetFile}`);
await promiseMe(callback => fs.writeFile(targetFile, countryHtml, callback)); await promiseMe(callback => fs.writeFile(targetFile, countryHtml, callback));
console.log(`wrote to ${targetFile} in ${Date.now() - start}ms`); console.log(`[country:${countryData.name}] wrote to ${targetFile} in ${Date.now() - start}ms`);
if (countryData.states.length) {
await Promise.all(countryData.states.map(async (stateData) => {
if (!stateData.name || !stateData.counties || !stateData.counties.length) {
return;
}
const start = Date.now();
const targetFile = path.join(publicDir, 'countries', countryData.safeName + '-' + stateData.safeName + '.html');
const stateHtml = stateFn({
data: stateData,
$title: stateData.name + ' - ' + countryData.name,
lastUpdate,
});
await promiseMe(callback => fs.writeFile(targetFile, stateHtml, callback));
console.log(`wrote to ${targetFile} in ${Date.now() - start}ms`);
}));
}
}));
for (const countryData of countryArr) {
if (!countryData.states) { if (!countryData.states) {
continue; continue;
} }
@ -735,6 +715,17 @@ const processRecords = async () => {
if (!stateData.name || !stateData.counties || !stateData.counties.length) { if (!stateData.name || !stateData.counties || !stateData.counties.length) {
continue; continue;
} }
const start = Date.now();
const targetFile = path.join(publicDir, 'countries', countryData.safeName + '-' + stateData.safeName + '.html');
const stateHtml = stateFn({
data: stateData,
$title: stateData.name + ', ' + countryData.name,
lastUpdate,
});
await promiseMe(callback => fs.writeFile(targetFile, stateHtml, callback));
console.log(`[state:${stateData.name}] wrote to ${targetFile} in ${Date.now() - start}ms`);
for (const countyData of stateData.counties) { for (const countyData of stateData.counties) {
countyData.population = countyData.population || 0; countyData.population = countyData.population || 0;
@ -750,7 +741,7 @@ const processRecords = async () => {
lastUpdate, lastUpdate,
}); });
await promiseMe(callback => fs.writeFile(targetFile, countyHtml, callback)); await promiseMe(callback => fs.writeFile(targetFile, countyHtml, callback));
console.log(`wrote to ${targetFile} in ${Date.now() - start}ms`); console.log(`[county:${countyData.state}-${countyData.name}] wrote to ${targetFile} in ${Date.now() - start}ms`);
} }
} }
} }