@@ -107,34 +107,40 @@ export async function fetchBulkModuleHealth(_event: H3Event, modules: BaseModule
107107
108108 if ( ! uncached . length ) return result
109109
110- console . info ( `Fetching health for ${ uncached . length } modules from nuxt.care...` )
111- try {
112- const query = new URLSearchParams ( )
113- query . set ( 'slim' , 'true' )
114- for ( const m of uncached ) {
115- query . append ( 'package' , m . npm )
116- }
117- const statusColorMap : Record < string , string > = {
118- optimal : '#22c55e' ,
119- stable : '#84cc16' ,
120- degraded : '#eab308' ,
121- critical : '#ef4444' ,
122- unknown : '#6b7280'
123- }
124- const data = await $fetch < NuxtCareModuleSlim [ ] > ( `https://nuxt.care/api/v1/modules?${ query . toString ( ) } ` )
125- for ( const item of data ) {
126- const module = uncached . find ( m => m . npm === item . npm )
127- if ( ! module ) continue
128- const health : ModuleHealth = {
129- score : item . score ,
130- color : statusColorMap [ item . status ] || '#6b7280' ,
131- status : item . status
110+ const CHUNK_SIZE = 50
111+ const statusColorMap : Record < string , string > = {
112+ optimal : '#22c55e' ,
113+ stable : '#84cc16' ,
114+ degraded : '#eab308' ,
115+ critical : '#ef4444' ,
116+ unknown : '#6b7280'
117+ }
118+ const npmToModule = new Map ( uncached . map ( m => [ m . npm , m ] ) )
119+
120+ console . info ( `Fetching health for ${ uncached . length } modules from nuxt.care (${ Math . ceil ( uncached . length / CHUNK_SIZE ) } chunks)...` )
121+ for ( let i = 0 ; i < uncached . length ; i += CHUNK_SIZE ) {
122+ const chunk = uncached . slice ( i , i + CHUNK_SIZE )
123+ try {
124+ const query = new URLSearchParams ( )
125+ query . set ( 'slim' , 'true' )
126+ for ( const m of chunk ) {
127+ query . append ( 'package' , m . npm )
128+ }
129+ const data = await $fetch < NuxtCareModuleSlim [ ] > ( `https://nuxt.care/api/v1/modules?${ query . toString ( ) } ` )
130+ for ( const item of data ) {
131+ const module = npmToModule . get ( item . npm )
132+ if ( ! module ) continue
133+ const health : ModuleHealth = {
134+ score : item . score ,
135+ color : statusColorMap [ item . status ] || '#6b7280' ,
136+ status : item . status
137+ }
138+ result [ module . name ] = health
139+ await kv . set ( `module:health:${ module . name } ` , health , { ttl : 60 * 60 * 24 } )
132140 }
133- result [ module . name ] = health
134- await kv . set ( `module:health: ${ module . name } ` , health , { ttl : 60 * 60 * 24 } )
141+ } catch ( err ) {
142+ console . error ( `Cannot fetch bulk health from nuxt.care (chunk ${ Math . floor ( i / CHUNK_SIZE ) + 1 } ): ${ err } ` )
135143 }
136- } catch ( err ) {
137- console . error ( `Cannot fetch bulk health from nuxt.care: ${ err } ` )
138144 }
139145
140146 return result
0 commit comments