summary refs log tree commit diff
path: root/scripts
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-09-27 22:17:22 +1000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-09-27 22:18:10 +1000
commitcf5637db1b161d234306dbfc98a46e31322c9524 (patch)
tree96c715aabf65b3bbc2c4d007ca3fa59a7356a726 /scripts
parentBad check for if buffer is json string instead of gzip (diff)
downloadserver-cf5637db1b161d234306dbfc98a46e31322c9524.tar.xz
Make client cacher suck less?
Diffstat (limited to 'scripts')
-rw-r--r--scripts/client.js28
1 files changed, 18 insertions, 10 deletions
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`);