@@ -805,16 +805,18 @@ export const fetchRecentDownloadStats = createServerFn({ method: 'POST' })
805805 // Add HTTP caching headers - shorter cache for recent data
806806 setResponseHeaders (
807807 new Headers ( {
808- 'Cache-Control' :
809- 'public, max-age=300, stale-while-revalidate=600' ,
808+ 'Cache-Control' : 'public, max-age=300, stale-while-revalidate=600' ,
810809 'Netlify-CDN-Cache-Control' :
811810 'public, max-age=300, durable, stale-while-revalidate=600' ,
812811 } ) ,
813812 )
814813
815814 // Import db functions dynamically
816- const { getRegisteredPackages, getBatchNpmDownloadChunks, setCachedNpmDownloadChunk } =
817- await import ( './stats-db.server' )
815+ const {
816+ getRegisteredPackages,
817+ getBatchNpmDownloadChunks,
818+ setCachedNpmDownloadChunk,
819+ } = await import ( './stats-db.server' )
818820
819821 // Get all registered packages for this library (includes framework adapters)
820822 let packageNames = await getRegisteredPackages ( data . library . id )
@@ -828,17 +830,41 @@ export const fetchRecentDownloadStats = createServerFn({ method: 'POST' })
828830 const todayStr = today . toISOString ( ) . substring ( 0 , 10 )
829831
830832 // Calculate date ranges
831- const dailyStart = new Date ( today . getTime ( ) - 24 * 60 * 60 * 1000 ) . toISOString ( ) . substring ( 0 , 10 )
832- const weeklyStart = new Date ( today . getTime ( ) - 7 * 24 * 60 * 60 * 1000 ) . toISOString ( ) . substring ( 0 , 10 )
833- const monthlyStart = new Date ( today . getTime ( ) - 30 * 24 * 60 * 60 * 1000 ) . toISOString ( ) . substring ( 0 , 10 )
833+ const dailyStart = new Date ( today . getTime ( ) - 24 * 60 * 60 * 1000 )
834+ . toISOString ( )
835+ . substring ( 0 , 10 )
836+ const weeklyStart = new Date ( today . getTime ( ) - 7 * 24 * 60 * 60 * 1000 )
837+ . toISOString ( )
838+ . substring ( 0 , 10 )
839+ const monthlyStart = new Date ( today . getTime ( ) - 30 * 24 * 60 * 60 * 1000 )
840+ . toISOString ( )
841+ . substring ( 0 , 10 )
834842
835843 // Create chunk requests for all packages and time periods
836844 const chunkRequests = [ ]
837845 for ( const packageName of packageNames ) {
838846 chunkRequests . push (
839- { packageName, dateFrom : dailyStart , dateTo : todayStr , binSize : 'daily' as const , period : 'daily' } ,
840- { packageName, dateFrom : weeklyStart , dateTo : todayStr , binSize : 'daily' as const , period : 'weekly' } ,
841- { packageName, dateFrom : monthlyStart , dateTo : todayStr , binSize : 'daily' as const , period : 'monthly' } ,
847+ {
848+ packageName,
849+ dateFrom : dailyStart ,
850+ dateTo : todayStr ,
851+ binSize : 'daily' as const ,
852+ period : 'daily' ,
853+ } ,
854+ {
855+ packageName,
856+ dateFrom : weeklyStart ,
857+ dateTo : todayStr ,
858+ binSize : 'daily' as const ,
859+ period : 'weekly' ,
860+ } ,
861+ {
862+ packageName,
863+ dateFrom : monthlyStart ,
864+ dateTo : todayStr ,
865+ binSize : 'daily' as const ,
866+ period : 'monthly' ,
867+ } ,
842868 )
843869 }
844870
@@ -908,23 +934,32 @@ export const fetchRecentDownloadStats = createServerFn({ method: 'POST' })
908934 dateFrom : req . dateFrom ,
909935 dateTo : req . dateTo ,
910936 binSize : req . binSize ,
911- totalDownloads : downloads . reduce ( ( sum : number , d : any ) => sum + d . downloads , 0 ) ,
937+ totalDownloads : downloads . reduce (
938+ ( sum : number , d : any ) => sum + d . downloads ,
939+ 0 ,
940+ ) ,
912941 dailyData : downloads ,
913942 isImmutable : false , // Recent data is mutable
914943 updatedAt : Date . now ( ) ,
915944 }
916945
917946 // Cache this chunk asynchronously
918947 setCachedNpmDownloadChunk ( chunkData ) . catch ( ( err ) =>
919- console . warn ( `Failed to cache recent downloads for ${ req . packageName } :` , err )
948+ console . warn (
949+ `Failed to cache recent downloads for ${ req . packageName } :` ,
950+ err ,
951+ ) ,
920952 )
921953
922954 return {
923955 key : `${ req . packageName } |${ req . dateFrom } |${ req . dateTo } |${ req . binSize } ` ,
924956 data : chunkData ,
925957 }
926958 } catch ( error ) {
927- console . error ( `Failed to fetch recent downloads for ${ req . packageName } :` , error )
959+ console . error (
960+ `Failed to fetch recent downloads for ${ req . packageName } :` ,
961+ error ,
962+ )
928963 // Return zero data on error
929964 return {
930965 key : `${ req . packageName } |${ req . dateFrom } |${ req . dateTo } |${ req . binSize } ` ,
0 commit comments