rb:n1-check

Detect N+1 query patterns in Rails and Grape codepaths.

7|Updated Mar 22, 2026
One-click install
npx skills add https://github.com/slbug/claude-ruby-grape-rails --skill rb-n1-check
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: rb:n1-check
Source: https://github.com/slbug/claude-ruby-grape-rails/tree/main/plugins/ruby-grape-rails/skills/ar-n1-check
Command: npx skills add https://github.com/slbug/claude-ruby-grape-rails --skill rb-n1-check

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Diagnoses and explains N+1 database query patterns that cause slow index pages, API responses, serializers, and Hotwire screens by identifying lazy association loads and missing preload strategies.

Core Features & Use Cases

  • Detection: Scans controllers, models, serializers, blueprints, and GraphQL codepaths to locate loops and access patterns that trigger N+1 queries.
  • Explanation & Fixes: Describes root causes such as serializer-induced repeated loads and missing includes, and recommends includes, preload, eager_load, or preloader APIs.
  • Best Practices: Suggests Bullet or strict_loading checks, batching, and query composition techniques to prevent regressions in production.

Quick Start

Use rb:n1-check to analyze the specified path or feature for N+1 queries, explain the cause, and suggest precise preload or eager loading fixes.

Frequently Asked Questions about rb:n1-check

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I find and fix N+1 queries in Rails controllers and serializers?▼

To fix N+1 queries in Rails, scan controllers, serializers, and GraphQL resolvers to locate lazy association loads inside loops, then apply preload, eager_load, or includes strategies to batch the database queries.

What causes N+1 queries in Grape API endpoints and serializers?▼

N+1 queries in Grape API endpoints are typically caused by serializer-induced repeated loads when associated data is accessed individually for each record, triggering a separate database query per iteration instead of a single batched load.

Does Bullet work with Rails strict_loading to prevent N+1 query regressions?▼

Bullet and Rails strict_loading both help prevent N+1 query regressions; Bullet detects lazy loads during testing while strict_loading enforces eager loading constraints, and combining them provides robust query optimization checks.

What is the best way to preload associations in Hotwire screens?▼

The best way to preload associations in Hotwire screens is to use includes, preload, or eager_load in the controller before rendering the view, ensuring associated data is fetched in a single batch query rather than triggering N+1 database loads.

How do I detect N+1 queries in GraphQL resolvers and nested API responses?▼

To detect N+1 queries in GraphQL resolvers and nested API responses, inspect the code paths for repeated single-record database queries triggered by nested object access, then apply preloader APIs or eager_load to batch the association loads.

When should I use preload versus eager_load or includes for query optimization in Active Record?▼

Use preload for separate batch queries without joins, eager_load when you need to filter by associated records using joins, and includes when you want Active Record to automatically choose between the two based on query conditions.