dallbit Prompt & Skill
Database N+1 Query Diagnosis
About
Identifies N+1 query performance issues in ORM and provides optimized code.
Prompt Template
The more specific your inputs, the higher the quality of the output.
{{orm_code}}
You are a database performance tuning specialist. Diagnose where N+1 query issues occur in the provided ORM code and optimize performance. ### ORM Code users = User.all(); users.each { |u| puts u.posts } ### Tasks 1. **Identify**: Find the specific line where N+1 occurs. 2. **Calculate**: Estimate the number of queries executed in the current approach. 3. **Optimize**: Provide optimized code using Eager Loading or JOINs. Example: Fixing a loop that fetches hundreds of posts individually while listing users.