Detects N+1 queries, suggests eager loading, and recommends database indexes
View on GitHubFebruary 2, 2026
Select agents to install to:
npx add-skill https://github.com/nbarthel/claudy/blob/5d4dc823a5e5605f0d8d004b6c8c97778d6b1b16/plugins/rails-workflow/skills/rails-performance-patterns/skill.md -a claude-code --skill rails-performance-patternsInstallation paths:
.claude/skills/rails-performance-patterns/# Rails Performance Patterns Skill
Automatically detects performance issues and suggests optimizations.
## What This Skill Does
**Automatic Detection:**
- N+1 query problems (missing eager loading)
- Missing database indexes on foreign keys
- Inefficient query patterns
- Large result sets without pagination
**When It Activates:**
- Model files with associations modified
- Controller actions that query models
- Iteration over associations detected
## Key Checks
### 1. N+1 Query Detection
**Problem Pattern:**
```ruby
# app/controllers/posts_controller.rb
def index
@posts = Post.all # 1 query
@posts.each do |post|
puts post.author.name # N queries (one per post)
end
end
```
**Skill Output:**
```
⚠️ Performance: Potential N+1 query
Location: app/controllers/posts_controller.rb:15
Issue: Accessing 'author' association in loop without eager loading
Fix: Add includes to eager load:
@posts = Post.includes(:author).all
```
**Solution:**
```ruby
def index
@posts = Post.includes(:author).all # 2 queries total
end
```
### 2. Missing Indexes
**Checks:**
- Foreign keys have indexes
- Commonly queried columns indexed
- Unique constraints have indexes
**Example:**
```ruby
# db/migrate/xxx_create_posts.rb
create_table :posts do |t|
t.references :user # ✅ Auto-creates index
t.string :slug # ❌ Missing index if queried often
end
```
**Skill Output:**
```
⚠️ Performance: Missing index recommendation
Location: app/models/post.rb:5
Issue: slug column used in where clauses without index
Add migration:
add_index :posts, :slug, unique: true
```
### 3. Pagination Missing
**Problem:**
```ruby
def index
@products = Product.all # ❌ Loads all 100k+ products
end
```
**Skill Output:**
```
⚠️ Performance: Large result set without pagination
Location: app/controllers/products_controller.rb:10
Issue: Loading all Product records (estimated 100k+ rows)
Recommendation: Add pagination
# Use kaminari or pagy
@products = Product.page(params[:page]).per(20)
`