From 86db79776560b8eb87003ab0609d28b78a662624 Mon Sep 17 00:00:00 2001 From: tmont Date: Thu, 23 Jul 2020 12:42:03 -0700 Subject: [PATCH] removed concurrency from generation script --- generate.js | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/generate.js b/generate.js index 11ded0f..9c64939 100755 --- a/generate.js +++ b/generate.js @@ -696,7 +696,7 @@ const processRecords = async () => { const stateFn = pug.compileFile(singleStateTmpl); const countyFn = pug.compileFile(singleCountyTmpl); - await Promise.all(countryArr.map(async (countryData) => { + for (const countryData of countryArr) { const start = Date.now(); const targetFile = path.join(publicDir, 'countries', countryData.safeName + '.html'); const countryHtml = countryFn({ @@ -704,29 +704,9 @@ const processRecords = async () => { $title: countryData.name, lastUpdate, }); - console.log(`writing to ${targetFile}`); 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) { continue; } @@ -735,6 +715,17 @@ const processRecords = async () => { if (!stateData.name || !stateData.counties || !stateData.counties.length) { 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) { countyData.population = countyData.population || 0; @@ -750,7 +741,7 @@ const processRecords = async () => { lastUpdate, }); 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`); } } }