Night Shift: add compound indexes for song queries#21
Conversation
The songProgress queries used .withIndex("by_user").filter(songId)
which scans all of a user's records to find one song. Added compound
indexes (by_user_song, by_user_song_line) to userSongProgress and
lineProgress tables, and updated all 6 affected queries to use them.
This eliminates table scans on the hot path (checkbox toggles, page loads).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThe changes introduce new composite database indices to the schema (by_user_song and by_user_song_line) and update corresponding query and mutation operations to leverage these indices for improved query efficiency. The public API signatures remain unchanged. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||
PR Code Suggestions ✨No code suggestions found for the PR. |
User description
Automated improvement by Golems Night Shift.
add compound indexes for song queries
PR Type
Enhancement
Description
Add compound indexes for user+song queries in database schema
Update 6 query methods to use new indexes instead of filtering
Eliminate table scans on hot path operations like checkbox toggles
Minor formatting and code style improvements
Diagram Walkthrough
File Walkthrough
schema.ts
Add compound indexes to schema tablesconvex/schema.ts
by_user_songcompound index touserSongProgresstableby_user_songandby_user_song_linecompound indexes tolineProgresstableoptimize queries
songProgress.ts
Replace filter operations with compound indexesconvex/songProgress.ts
getByUserSongto useby_user_songindex instead of filteringrecordLineCompletionto useby_user_songindex for lookupsrecordLinesCompletionto useby_user_songindex for existingrecord queries
toggleLineLearnedto useby_user_song_lineindex forlineProgress queries
getLineProgressByUserSongto useby_user_songindex instead offiltering
Summary by CodeRabbit