Detects N+1 queries, suggests eager loading, and recommends database indexes
Detects N+1 queries, suggests eager loading, and recommends database indexes
/plugin marketplace add nbarthel/claudy/plugin install rails-workflow@claudyThis skill inherits all available tools. When active, it can use any tool Claude has access to.
Automatically detects performance issues and suggests optimizations.
Automatic Detection:
When It Activates:
Problem Pattern:
# 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:
def index
@posts = Post.includes(:author).all # 2 queries total
end
Checks:
Example:
# 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
Problem:
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)
Pattern:
# Without counter cache
@user.posts.count # Runs COUNT(*) query every time
# With counter cache
@user.posts_count # Reads from cached column
Skill Output:
ℹ️ Performance: Counter cache opportunity
Location: app/views/users/show.html.erb:12
Pattern: Frequently accessing post count
Add to migration:
add_column :users, :posts_count, :integer, default: 0
Update association:
belongs_to :user, counter_cache: true
# .rails-performance.yml
n1_detection:
enabled: true
severity: warning
indexes:
check_foreign_keys: true
check_query_columns: true
pagination:
warn_threshold: 1000
require_for_large_tables: true
counter_cache:
suggest_threshold: 3 # Suggest if accessed 3+ times
Add instrumentation:
# config/initializers/query_monitoring.rb
ActiveSupport::Notifications.subscribe('sql.active_record') do |*args|
event = ActiveSupport::Notifications::Event.new(*args)
if event.duration > 100 # Log slow queries
Rails.logger.warn("Slow query (#{event.duration}ms): #{event.payload[:sql]}")
end
end
Eager Loading:
# N+1
Post.all.each { |p| p.author.name }
# Fixed: includes (left join)
Post.includes(:author).each { |p| p.author.name }
# Fixed: preload (separate queries)
Post.preload(:author).each { |p| p.author.name }
# Fixed: eager_load (always joins)
Post.eager_load(:author).each { |p| p.author.name }
Select Specific Columns:
# Loads all columns
Post.all
# Loads only needed columns
Post.select(:id, :title, :created_at)
Batch Processing:
# Loads all at once
Post.all.each { |p| process(p) }
# Loads in batches of 1000
Post.find_each(batch_size: 1000) { |p| process(p) }
This skill helps you build fast Rails applications from the start.
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.