Skip to content

Commit 3eaf31a

Browse files
committed
fix(analytics): publicPlatformStats now shows all-time data instead of last 1000 sessions
1 parent 3c29de2 commit 3eaf31a

6 files changed

Lines changed: 43 additions & 443 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ dist/
2929
# Documentation (internal)
3030
docs/
3131

32-
32+
# Disabled pages
33+
src/pages/Stats.tsx

changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff 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)

convex/analytics.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff 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
699700
export 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

0 commit comments

Comments
 (0)