Parallelize reading files
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Cat /dev/Nulo 2022-11-25 22:18:10 -03:00
parent d36f62ea2b
commit a624f664ef

View file

@ -129,15 +129,17 @@ interface Reports {
let reports: Reports = {};
async function recurseDirectory(reports: Reports, path: string) {
const dir = await readdir(path, { withFileTypes: true });
for (const file of dir) {
const filePath = join(path, file.name);
if (file.isDirectory()) await recurseDirectory(reports, filePath);
else {
if (!file.name.endsWith(".html")) continue;
const content = await readFile(filePath, "utf-8");
reports[filePath] = await processFile(content);
}
}
return await Promise.all(
dir.map(async (file) => {
const filePath = join(path, file.name);
if (file.isDirectory()) await recurseDirectory(reports, filePath);
else {
if (!file.name.endsWith(".html")) return;
const content = await readFile(filePath, "utf-8");
reports[filePath] = await processFile(content);
}
})
);
}
await recurseDirectory(reports, dirPath);
const totalThings = Object.values(reports)