Skip to content

improvement(performance): added new indexes for improved session performance#1215

Merged
waleedlatif1 merged 1 commit intostagingfrom
improvement/performance
Sep 1, 2025
Merged

improvement(performance): added new indexes for improved session performance#1215
waleedlatif1 merged 1 commit intostagingfrom
improvement/performance

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

added new indexes for improved session performance + other indexes that are recommended by better-auth to optimize for performance ref

Type of Change

  • New feature

Testing

N/A

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 Sep 1, 2025

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

Project Deployment Preview Comments Updated (UTC)
sim Building Building Preview Comment Sep 1, 2025 10:59pm
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Sep 1, 2025 10:59pm

@waleedlatif1 waleedlatif1 merged commit f75c807 into staging Sep 1, 2025
3 of 4 checks passed
@waleedlatif1 waleedlatif1 deleted the improvement/performance branch September 1, 2025 23:00
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 adds 8 new database indexes to optimize authentication and session-related query performance. The changes follow better-auth performance recommendations and target commonly queried columns across five tables:

  • Session table: Indexes on userId and token columns for faster session validation and user session lookups
  • Account table: Index on userId for OAuth and credential account queries
  • Verification table: Index on identifier for email verification and password reset flows
  • Member table: Indexes on userId and organizationId for organization membership queries
  • Invitation table: Indexes on email and organizationId for invitation lookups

The implementation includes updates to the Drizzle ORM schema definitions in schema.ts and generates the corresponding migration files (0082_light_blockbuster.sql and associated metadata). All indexes use PostgreSQL B-tree structure and follow standard naming conventions. The changes are purely additive with no modifications to existing table structures or data types, making this a safe performance enhancement that should significantly improve query speeds for authentication flows, session management, and organization-related operations.

Confidence score: 4/5

  • This PR is safe to merge with minimal risk as it only adds performance-optimizing indexes without modifying existing schema
  • Score reflects well-structured database optimization following established best practices, though one index may be redundant
  • Pay close attention to the session_token_idx as it may duplicate existing unique constraint functionality

4 files reviewed, no comments

Edit Code Review Bot Settings | Greptile

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.

1 participant