improvement(performance): added new indexes for improved session performance#1215
improvement(performance): added new indexes for improved session performance#1215waleedlatif1 merged 1 commit intostagingfrom
Conversation
There was a problem hiding this comment.
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
userIdandtokencolumns for faster session validation and user session lookups - Account table: Index on
userIdfor OAuth and credential account queries - Verification table: Index on
identifierfor email verification and password reset flows - Member table: Indexes on
userIdandorganizationIdfor organization membership queries - Invitation table: Indexes on
emailandorganizationIdfor 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
Summary
added new indexes for improved session performance + other indexes that are recommended by better-auth to optimize for performance ref
Type of Change
Testing
N/A
Checklist