Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

Description

added indexes to speed up logs loading time, modified to only display logs for current workspace, decr logs lookup time from O(n) to O(log(n))

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Performance improvement

How Has This Been Tested?

Tested manually across workspaces, ensured that we only see the logs for that workspace

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • All tests pass locally and in CI (bun run test)
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules
  • I have updated version numbers as needed (if needed)
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Security Considerations:

  • My changes do not introduce any new security vulnerabilities
  • I have considered the security implications of my changes

@vercel
Copy link

vercel bot commented Jul 23, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sim ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 23, 2025 11:24pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
docs ⬜️ Skipped (Inspect) Jul 23, 2025 11:24pm

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.

Greptile Summary

This PR implements database performance optimizations for logs by adding strategic indexes to the workflow and workflow_logs tables. The changes include five new B-tree indexes:

  • workflow_user_id_idx on the workflow table's user_id column
  • workflow_workspace_id_idx on the workflow table's workspace_id column
  • workflow_user_workspace_idx as a composite index on user_id and workspace_id
  • workflow_logs_workflow_id_idx on the workflow_logs table's workflow_id column
  • workflow_logs_workflow_created_idx as a composite index on workflow_id and created_at

These indexes are designed to optimize the common query patterns used when filtering logs by workspace membership. The PR addresses a performance bottleneck where log queries were previously performing full table scans (O(n) complexity) by enabling efficient indexed lookups (O(log(n)) complexity). The workspace-scoped filtering ensures users only see logs for workflows within their current workspace, which requires joining workflow_logs → workflow → workspace_member tables - operations that these indexes make highly efficient.

The changes integrate seamlessly with the existing database schema architecture, following established patterns for multi-tenant workspace isolation. The migration includes proper snapshot versioning and journal entries to maintain database schema consistency across deployments.

Confidence score: 5/5

• This PR is extremely safe to merge - it only adds performance-optimizing indexes without modifying any data or application logic
• The indexes follow standard PostgreSQL best practices and target well-defined query patterns that clearly benefit from indexing
• No files need additional attention - the migration is straightforward and all changes are properly coordinated

4 files reviewed, no comments

Edit Code Review Bot Settings | Greptile

@vercel vercel bot temporarily deployed to Preview – docs July 23, 2025 23:19 Inactive
@waleedlatif1 waleedlatif1 merged commit 258419d into staging Jul 23, 2025
3 of 4 checks passed
@waleedlatif1 waleedlatif1 deleted the improvement/logs-permissions branch July 23, 2025 23:20
arenadeveloper02 pushed a commit to arenadeveloper02/p2-sim that referenced this pull request Sep 19, 2025
…nly display logs for current workspace (simstudioai#773)

* added indexes to speed up logs loading time, modified to only display logs for current workspace

* remove user check, rely on source-of-truth permissions to display logs
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