File tree Expand file tree Collapse file tree 1 file changed +19
-6
lines changed
Expand file tree Collapse file tree 1 file changed +19
-6
lines changed Original file line number Diff line number Diff 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+
8694const 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 != '' ) {
You can’t perform that action at this time.
0 commit comments