Skip to content

Commit d746bfa

Browse files
committed
fix: Make the console errors process more parallelized
1 parent 0dbacc6 commit d746bfa

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

tasks/console-errors.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,28 @@ const checkPage = async (url) => {
8383
return errorsFound;
8484
};
8585

86+
function chunkArray(array, chunkSize) {
87+
const result = [];
88+
for (let i = 0; i < array.length; i += chunkSize) {
89+
result.push(array.slice(i, i + chunkSize));
90+
}
91+
return result;
92+
}
93+
8694
const consoleErrors = async (domain) => {
8795
const pagesToCheck = await getSitemapUrls(domain);
96+
const pagesToCheckChunks = chunkArray(pagesToCheck, 20);
8897
let errorMessage = '';
89-
for (let i = 0; i < pagesToCheck.length; i++) {
90-
const url = pagesToCheck[i];
91-
console.log(`checking page ${url}`);
92-
const errorsFound = await checkPage(url);
93-
errorsFound.forEach((error) => {
94-
errorMessage += `${error.message} found on ${error.page}\n`;
98+
for (let i = 0; i < pagesToCheckChunks.length; i++) {
99+
const urls = pagesToCheck[i];
100+
const errorsFoundGroups = urls.map((url) => {
101+
console.log(`checking page ${url}`);
102+
return checkPage(url);
103+
});
104+
await Promise.all(errorsFoundGroups).then((errorsFound) => {
105+
errorsFound.forEach((error) => {
106+
errorMessage += `${error.message} found on ${error.page}\n`;
107+
});
95108
});
96109
}
97110
if (errorMessage != '') {

0 commit comments

Comments
 (0)