perf: add indexes on high-traffic foreign keys and sort columns#666
perf: add indexes on high-traffic foreign keys and sort columns#666neuron-tech-ai wants to merge 1 commit into
Conversation
Queries throughout the codebase filter on generations.profile_id, generations.status, generations.created_at, story_items.story_id, story_items.generation_id, generation_versions.generation_id, and profile_samples.profile_id with every request. Without indexes SQLite falls back to a full table scan; as history grows (hundreds or thousands of generations) these scans become the dominant latency. Changes: - Add index=True on the most-queried FK and sort columns in models.py so new installs get them from Base.metadata.create_all - Add _migrate_add_indexes() called from run_migrations() so existing installs get the same indexes on next startup (uses CREATE INDEX IF NOT EXISTS — idempotent, <10 ms on any realistic dataset)
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ 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 |
Several high-traffic query patterns were doing full table scans due to missing indexes:
generation_history: missing index onprofile_id(queried on every history load) andcreated_at(sort column)profile_samples: missing index onprofile_idcaptures: missing index oncreated_at(sort column)These are the most common query patterns in normal use. At small library sizes the scans are fine; at scale (hundreds of generations, many captures) they become the bottleneck. Adding the indexes is safe and has no downside.