Skip to content
cccskills
FreePublished on GitHub

Laravel Eloquent N+1 and Query Efficiency Review

Detects N+1 query patterns (relation access inside loops without eager loading), full-table get()/all() loads, and unsafe chunk()/cursor() usage in Laravel Eloquent code.

The English summary is being prepared. Showing the original description.

Run score Not tested

See how to install

Files included (4)

  • SKILL.md3.5 KB
  • fixtures/01-nplus1-loop-happy.md866 B
  • fixtures/02-eager-loaded-guard.md873 B
  • golden/01-nplus1-loop-happy.md502 B

SKILL.md (original)

Review the instructions the agent will receive before you install.

Pattern declaration

Primary pattern: Reviewer Secondary patterns: Inversion Why: Eloquent のクエリ効率規約への適合をチェックリスト型で検査する

Goal / 目的

  • ループ内 relation アクセスによる N+1 クエリ(公式例: 25 件で 26 クエリ)を検出する。
  • 巨大テーブルの全件ロード(all() / get())と、chunk() / cursor() の誤用を検出する。

Non-goals / 扱わないこと

  • mass assignment / 認可(laravel-mass-assignment のスコープ)。
  • migration の安全性(laravel-migration-safety のスコープ)。
  • SQL チューニング一般・index 設計。

Pre-execution Gate / 実行前ゲート

このスキルは以下の条件がすべて満たされない限りNO_REVIEWを返す。

  • 差分に Eloquent モデルのクエリ・relation アクセスの追加変更が含まれている
  • diff コンテキストが利用可能である

ゲート不成立時の出力: NO_REVIEW: laravel-eloquent-nplus1 — Eloquent クエリの変更なし

False-positive guards / 抑制条件

  • ループ前に with() / load() 済みの relation へのアクセスは指摘しない(diff 外で eager load されている可能性があるため、確証がなければ質問に留める)。
  • ループ対象が少数固定(config 由来等)の場合の relation アクセスは指摘しない。
  • chaperone() を使った親逆参照は正当。
  • preventLazyLoading が有効なプロジェクトでは N+1 がテストで落ちるため、重複指摘を避ける。

Rule / ルール

  • ループ内で relation を参照する場合は with('relation')(取得後なら load() / loadCount())で eager load する。
  • 巨大テーブルの反復は chunkById / lazyById / cursor を使う。
  • chunk() でフィルタ対象カラムを更新しない(公式: inconsistent results。chunkById を使う)。
  • cursor() と eager loading を併用しない(cursor は relation を eager load できない。lazy を使う)。
  • chunkById / lazyById で orWhere を含む条件は closure で論理グループ化する。

Evidence / 根拠の取り方

  • 指摘は <file>:<line> で差分に紐づけ、公式規約(laravel.com/docs/12.x/eloquent-relationships#eager-loading 等)を 1 行で添える。
  • eager load の有無が diff から確定できない場合は断定せず questions で返す。

Output / 出力(短文版の推奨)

コメントは日本語で返す。

  • Finding: N+1 / 全件ロード / chunk 誤用のどれか(1文)
  • Impact: クエリ数 / メモリ / 一貫性への影響
  • Fix: with() / chunkById / lazy 等の最小修正案

Sources / 出典

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

<What this skill does>

The English summary is being prepared. Showing the original description.

s977043/river-review7Updated Oct 24, 2026

画像・ボタン・フォーム要素に適切なアクセシブルネームがあるか確認する。

The English summary is being prepared. Showing the original description.

s977043/river-review7Updated Oct 24, 2026

Ensure ADRs capture context, decision, alternatives, tradeoffs, and follow-ups in a way that prevents future drift.

The English summary is being prepared. Showing the original description.

s977043/river-review7Updated Oct 24, 2026

敵対的分析手法を統合したレビューの entry skill。認知バイアス対策の3手法 (Pre-mortem / War Game / Logic Torturing)と、宣言・主張と実態の乖離を突く claim-vs-actual 検出3パターン(Self-Contradiction / Refactor-Claim Audit / Cross-File Leakage)へルーティングし、通常のレビューでは見えない設計の盲点・ 防御の穴・論理の弱点・宣言と実装のズレを可視化する。

The English summary is being prepared. Showing the original description.

s977043/river-review7Updated Oct 24, 2026

Review changes to the Agent Skills import/export bridge for path safety, round-trip fidelity, and validation correctness.

The English summary is being prepared. Showing the original description.

s977043/river-review7Updated Oct 24, 2026

Checks whether AI-assisted work defines review criteria, accessible context, explicit review loop, human judgment boundary, and feedback capture before delegating to an agent.

The English summary is being prepared. Showing the original description.

s977043/river-review7Updated Oct 24, 2026

See all skills by s977043

Report a problem with this skill