@@ -635,21 +635,23 @@ export const summaryStats = query({
635635} ) ;
636636
637637// TEMP: Public message count for milestone display on stats page
638- // Sums messageCount from sessions table (fewer docs, avoids 16MB read limit )
638+ // Sums messageCount from sessions table (limit 5000 to prevent timeout )
639639export const publicMessageCount = query ( {
640640 args : { } ,
641641 returns : v . number ( ) ,
642642 handler : async ( ctx ) => {
643+ // Limit to 5000 sessions to prevent query timeout
644+ const sessions = await ctx . db . query ( "sessions" ) . take ( 5000 ) ;
643645 let total = 0 ;
644- for await ( const session of ctx . db . query ( " sessions" ) ) {
646+ for ( const session of sessions ) {
645647 total += session . messageCount || 0 ;
646648 }
647649 return total ;
648650 } ,
649651} ) ;
650652
651- // TEMP: Public message growth data for animated chart on stats page
652- // Groups by session createdAt date and sums messageCount (avoids 16MB read limit )
653+ // TEMP: Public message growth data for chart on stats page
654+ // Groups by session createdAt date and sums messageCount (limit 5000 to prevent timeout )
653655export const publicMessageGrowth = query ( {
654656 args : { } ,
655657 returns : v . array (
@@ -660,10 +662,13 @@ export const publicMessageGrowth = query({
660662 } )
661663 ) ,
662664 handler : async ( ctx ) => {
665+ // Limit to 5000 sessions to prevent query timeout
666+ const sessions = await ctx . db . query ( "sessions" ) . take ( 5000 ) ;
667+
663668 // Group sessions by date and sum their messageCount
664669 const byDate : Record < string , number > = { } ;
665670
666- for await ( const session of ctx . db . query ( " sessions" ) ) {
671+ for ( const session of sessions ) {
667672 if ( ! session . createdAt || typeof session . createdAt !== "number" ) continue ;
668673 try {
669674 const dateObj = new Date ( session . createdAt ) ;
0 commit comments