Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

  • added logs stats endpoint to compute stats on server side and avoid limit in execution dashboard

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Jan 15, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Review Updated (UTC)
docs Skipped Skipped Jan 15, 2026 2:37am

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 15, 2026

Greptile Summary

This PR moves dashboard statistics computation from client-side to server-side to eliminate the 10,000 row limit that was preventing accurate metrics for large datasets.

Key changes:

  • New /api/logs/stats endpoint performs SQL aggregation directly in the database, computing metrics across all matching logs without row limits
  • Client-side aggregation logic removed from dashboard.tsx - now consumes pre-computed stats
  • React Query hook refactored from useDashboardLogs to useDashboardStats to match new data flow
  • Langsmith block cleaned up by removing unreachable switch case

Implementation approach:
The endpoint groups logs by workflow and time segment using SQL, then merges any overlapping segments that map to the same index. This ensures accurate weighted averages for duration metrics and complete execution counts. All filtering (workspace, time range, level, workflows, folders, triggers, search) is handled in the SQL query via buildFilterConditions.

Confidence Score: 4/5

  • This PR is safe to merge with minimal risk after addressing the averaging calculation issue that was already flagged
  • The refactor is well-structured with clear separation of concerns and proper error handling. The SQL aggregation approach is sound, and the frontend simplification reduces complexity. The previously identified averaging issue needs resolution, but otherwise the implementation is solid with appropriate auth, validation, and type safety.
  • Pay close attention to apps/sim/app/api/logs/stats/route.ts lines 170-181 where segment merging occurs - the averaging calculation needs review per existing thread

Important Files Changed

Filename Overview
apps/sim/app/api/logs/stats/route.ts New endpoint computing dashboard stats server-side using SQL aggregation. Handles auth, filters, time bounds, and aggregates metrics by workflow and time segments.
apps/sim/hooks/queries/logs.ts Updated React Query hook to fetch pre-aggregated stats from new endpoint instead of raw logs. Clean refactor with improved type exports.
apps/sim/app/workspace/[workspaceId]/logs/components/dashboard/dashboard.tsx Removed client-side aggregation logic, now consumes pre-computed stats from server. Simplified component with better separation of concerns.

Sequence Diagram

sequenceDiagram
    participant Client as Dashboard Component
    participant Hook as useDashboardStats Hook
    participant API as /api/logs/stats
    participant DB as Database
    
    Client->>Hook: Request dashboard data with filters
    Hook->>API: GET /api/logs/stats?workspaceId=...&filters...
    API->>API: Validate session & permissions
    API->>DB: Query time bounds (MIN/MAX startedAt)
    DB-->>API: Return bounds
    API->>API: Calculate segment size (totalMs / segmentCount)
    API->>DB: Aggregate query with GROUP BY workflow + segment
    Note over DB: SQL computes COUNT, AVG(duration)<br/>per workflow per time segment
    DB-->>API: Return aggregated rows
    API->>API: Merge overlapping segments<br/>(when DB rows map to same segment index)
    API->>API: Fill missing segments with zeros
    API->>API: Compute aggregate stats across workflows
    API-->>Hook: Return DashboardStatsResponse
    Hook-->>Client: Provide stats data
    Client->>Client: Transform WorkflowStats to WorkflowExecution
    Client->>Client: Render charts with pre-computed data
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@waleedlatif1
Copy link
Collaborator Author

@greptile

@waleedlatif1 waleedlatif1 merged commit 5af72ea into staging Jan 15, 2026
11 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/dashboard branch January 15, 2026 02:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants