File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,13 +6,6 @@ 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-
169### Added
1710
1811- pi-opensync-plugin community plugin support (syncs Pi coding agent sessions)
Original file line number Diff line number Diff line change @@ -695,8 +695,7 @@ 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 ALL-TIME usage
699- // Uses async iteration to process all sessions without hitting read limits
698+ // Returns top models and top CLI sources sorted by usage
700699export const publicPlatformStats = query ( {
701700 args : { } ,
702701 returns : v . object ( {
@@ -716,15 +715,24 @@ export const publicPlatformStats = query({
716715 ) ,
717716 } ) ,
718717 handler : async ( ctx ) => {
719- // Aggregate by model (all-time)
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
720729 const modelMap : Record < string , { totalTokens : number ; sessions : number } > =
721730 { } ;
722- // Aggregate by source/ CLI tool (all-time )
731+ // Aggregate by source ( CLI tool)
723732 const sourceMap : Record < string , { sessions : number ; totalTokens : number } > =
724733 { } ;
725734
726- // Use async iteration to process ALL sessions without memory limits
727- for await ( const s of ctx . db . query ( "sessions" ) ) {
735+ for ( const s of sessions ) {
728736 // Safe token value (handle null/undefined)
729737 const tokens = s . totalTokens ?? 0 ;
730738
You can’t perform that action at this time.
0 commit comments