From cf5637db1b161d234306dbfc98a46e31322c9524 Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Tue, 27 Sep 2022 22:17:22 +1000 Subject: Make client cacher suck less? --- scripts/client.js | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'scripts') diff --git a/scripts/client.js b/scripts/client.js index 2be0d5ea..cba36170 100644 --- a/scripts/client.js +++ b/scripts/client.js @@ -68,6 +68,7 @@ const doPatch = (content) => { const processFile = async (name) => { const res = await fetch(`${BASE_URL}/assets/${name}.js`); + if (res.status !== 200) return []; let text = await res.text(); text = doPatch(text); @@ -105,6 +106,8 @@ const processFile = async (name) => { let lastFinished = Date.now(); let previousFinish = Date.now(); + let promises = []; + for (var i = 0; i < assets.length; i++) { const asset = assets[i]; @@ -122,19 +125,24 @@ const processFile = async (name) => { process.stdout.cursorTo(0); process.stdout.write( `Caching asset ${asset}. ` + - `${i}/${assets.length - 1} = ${Math.floor( - (i / (assets.length - 1)) * 100, - )}% ` + - `Finish at: ${new Date( - Date.now() + finishTime, - ).toLocaleTimeString()}`, + `${i}/${assets.length - 1} = ${Math.floor( + (i / (assets.length - 1)) * 100, + )}% ` + + `Finish at: ${new Date( + Date.now() + finishTime, + ).toLocaleTimeString()}`, ); - await processFile(asset); + promises.push(processFile(asset)); - lastFinished = Date.now(); - rates.push(lastFinished - previousFinish); - previousFinish = lastFinished; + if (promises.length > 100) { + const values = await Promise.all(promises); + assets.push(...values.flat()); + promises = []; + lastFinished = Date.now(); + rates.push(lastFinished - previousFinish); + previousFinish = lastFinished; + } } console.log(`\nDone`); -- cgit 1.4.1