File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2929# Documentation (internal)
3030docs /
3131
32-
32+ # Disabled pages
33+ src /pages /Stats.tsx
Original file line number Diff line number Diff line change @@ -6,6 +6,13 @@ Format based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66
77## [ Unreleased]
88
9+ ### Fixed
10+
11+ - Fixed publicPlatformStats query showing only recent 1000 sessions instead of all-time data
12+ - Changed from .take(1000) to async iteration for true all-time aggregation
13+ - Top Models and Top CLI on homepage now show accurate all-time totals
14+ - Uses same pattern as publicMessageCount and publicMessageGrowth queries
15+
916### Added
1017
1118- pi-opensync-plugin community plugin support (syncs Pi coding agent sessions)
Original file line number Diff line number Diff line change @@ -695,7 +695,8 @@ export const publicMessageGrowth = query({
695695} ) ;
696696
697697// Public platform-wide stats for homepage leaderboard (no auth required)
698- // Returns top models and top CLI sources sorted by usage
698+ // Returns top models and top CLI sources sorted by ALL-TIME usage
699+ // Uses async iteration to process all sessions without hitting read limits
699700export const publicPlatformStats = query ( {
700701 args : { } ,
701702 returns : v . object ( {
@@ -715,24 +716,15 @@ export const publicPlatformStats = query({
715716 ) ,
716717 } ) ,
717718 handler : async ( ctx ) => {
718- // Fetch recent sessions for platform-wide stats (limit to 1000 to avoid timeout)
719- const sessions = await ctx . db . query ( "sessions" ) . order ( "desc" ) . take ( 1000 ) ;
720-
721- if ( sessions . length === 0 ) {
722- return {
723- topModels : [ ] ,
724- topSources : [ ] ,
725- } ;
726- }
727-
728- // Aggregate by model
719+ // Aggregate by model (all-time)
729720 const modelMap : Record < string , { totalTokens : number ; sessions : number } > =
730721 { } ;
731- // Aggregate by source ( CLI tool)
722+ // Aggregate by source/ CLI tool (all-time )
732723 const sourceMap : Record < string , { sessions : number ; totalTokens : number } > =
733724 { } ;
734725
735- for ( const s of sessions ) {
726+ // Use async iteration to process ALL sessions without memory limits
727+ for await ( const s of ctx . db . query ( "sessions" ) ) {
736728 // Safe token value (handle null/undefined)
737729 const tokens = s . totalTokens ?? 0 ;
738730
You can’t perform that action at this time.
0 commit comments