mcpField
L
laravel:performance-eager-loading

laravel:performance-eager-loading

github.com/jpcaparasDevelopment157171 installsUpdated 17w ago
Repository

About laravel:performance-eager-loading

A Laravel skill for preventing N+1 queries and reducing relation-loading overhead. It covers eager loading, lazy-loading safeguards, and query verification for developers optimizing database access.

Key features

  1. 01Explicit eager loading
  2. 02Post-fetch relation loading
  3. 03Development lazy-loading safeguards
  4. 04Query-count verification

Use cases

  1. 01Reduce relation queries in paginated results
  2. 02Detect accidental lazy loading in development
  3. 03Check query counts with tests or debugging tools

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/jpcaparas/superpowers-laravel --skill laravel:performance-eager-loading

After installing, type/laravel:performance-eager-loadingin Claude Code to confirm it loaded.

Details

From the project README

Eager Loading and N+1 Prevention

Load Relations Explicitly

Post::with(['author', 'comments'])->paginate();
  • Use load()/loadMissing() after fetching models when needed
  • Select only required columns for both base query and relations

Guard Against Lazy Loading in Dev/Test

Add to a service provider (non-production):

Model::preventLazyLoading(! app()->isProduction());

Verify

  • Use a query logger or debugbar to confirm relation queries are minimized
  • Add tests that assert counts or avoid unexpected query spikes

Comments

Markdown supported