lc-slow-queries
Detect queries without indexes, queries in loops, and unbounded selects.
Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Menu
Detect queries without indexes, queries in loops, and unbounded selects.
Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Baseado na classificação ocupacional SOC
Create a Larascraper scraper (v2 or v3) for a target website, chaining browser actions (click, type, wait, scroll), conditional flow (when/repeatUntil), captcha solving, and file/PDF downloads. Detects the installed major and generates the matching style.
Add or edit a Laracrate file collection in config/laracrate.php with the correct anatomy (disk, access, types, variants, previews, extract/embed, flags, per-model scoping).
Runtime-verified Laravel inspection using the Laravel Boost MCP server (Tinker, Database Query/Schema, Last Error) instead of static grep. Falls back to Docker/Tinker if Boost is not installed.
Scaffold spatie/laravel-permission setup - add the HasRoles trait to a model and generate a roles & permissions seeder.
Audit spatie/laravel-permission usage - permissions used in code but undefined, defined but unused, unprotected routes, guard mismatches, and cache pitfalls.
Extract business logic from a controller or Livewire component method into a Laractions Action class.
| name | lc:slow-queries |
| description | Detect queries without indexes, queries in loops, and unbounded selects. |
| argument-hint | [analyze | fix | fix --dry-run | file-path | fix file-path] |
| user-invocable | true |
| allowed-tools | Read Grep Bash Edit Write Glob |
Detect potential slow queries through static analysis: missing indexes, queries inside loops, unbounded selects, and foreign key columns without indexes.
| Subcommand | Description |
|---|---|
| (no argument) | Scan the entire project for slow query patterns. Read-only report. |
fix | Generate migration(s) to add missing indexes. Asks for confirmation before each change. |
fix --dry-run | Show what index migrations would be generated without writing anything. |
[file-path] | Analyze a specific file for slow query patterns. Read-only. |
fix [file-path] | Fix slow query issues originating from a specific file, with confirmation. |
What to detect:
Columns used in where(), whereHas(), orderBy(), groupBy(), and having() clauses that lack a corresponding index in migrations.
How to scan:
Grep to find all query builder calls with column references:
->where('column_name', and ->where(['column_name' =>->whereHas('relation', (check the closure for column references)->orderBy('column_name')->groupBy('column_name')->having('column_name',$table->index('column_name') or $table->index(['column_name', ...])$table->unique('column_name') (unique indexes also serve as indexes)->primary(), ->unique(), or ->index()$table->foreignId('column_name') -- some databases auto-index FK columns, some don'tSeverity: Medium (depends on table size)
Fix: Generate a migration to add the missing index.
What to detect:
Database queries executed inside foreach, for, while, array_map, collect()->each(), or similar iteration constructs.
How to scan:
Grep to find loop constructs in PHP files.Read to load each file with loops and check for query builder or Eloquent calls inside the loop body:
Model::where(, Model::find(, Model::create(DB::table(, DB::select(->save(), ->update(), ->delete()->first(), ->get(), ->count()lc:find-n-plus-one)Severity: High (multiplied by loop iteration count)
Fix: Suggest refactoring to bulk operations:
Model::find($id) in loop -> Model::whereIn('id', $ids)->get()->keyBy('id')->save() in loop -> Model::upsert($records, ...)->create() in loop -> Model::insert($records)What to detect:
Queries using ->get() without ->limit(), ->take(), or ->paginate() on tables that could grow large.
How to scan:
Grep to find all ->get() calls (excluding ->get('key') which is Collection::get).->limit() or ->take() present -> safe->paginate() or ->simplePaginate() present -> safe->where() with a highly selective condition (e.g., where('id', $id)) -> safetimestamps() and many migration modifications are likely largeSeverity: Medium (could cause memory issues on large tables)
Fix: Suggest adding ->limit() or converting to ->paginate().
What to detect:
Foreign key columns defined in migrations without explicit indexes. While some databases (MySQL InnoDB) auto-create indexes for FK constraints, columns used as FKs via convention (ending in _id) but without actual FK constraints will not have indexes.
How to scan:
_id._id column has:
->foreign() constraint (MySQL auto-indexes these)->index() definition->foreignId() call (creates both column and index via constraint)_id columns that have neither a FK constraint nor an explicit index.Severity: Medium
Fix: Generate a migration to add indexes on unindexed FK columns.
What to detect: Queries that select all columns when only a few are needed, especially on wide tables.
How to scan:
Grep to find queries without ->select() on tables with many columns (15+).Model::all() usage.->get() without a preceding ->select().Severity: Low (performance impact varies by table width)
Fix: Suggest adding ->select() with only needed columns, especially in list/index views.
SLOW QUERY ANALYSIS
====================
CRITICAL (queries in loops)
----------------------------
1. Query inside foreach loop
File: app/Services/PropertyService.php:78
Loop: foreach ($propertyIds as $id)
Query: Property::find($id)
Impact: ~100 queries per request (estimated from context)
Fix: Refactor to Property::whereIn('id', $propertyIds)->get()
HIGH (missing indexes on frequently queried columns)
-----------------------------------------------------
1. Missing index on 'properties.status'
Queried in: 4 files
- app/Http/Controllers/PropertyController.php:32
- resources/views/livewire/properties/index.blade.php:15
- app/Services/SearchService.php:44
- app/Jobs/SyncPropertyJob.php:22
Table estimated size: Large (15+ migrations)
Fix: Add index migration
MEDIUM (unbounded selects)
---------------------------
1. Unbounded ->get() on 'activities' table
File: app/Http/Controllers/DashboardController.php:18
Query: Activity::where('organization_id', $id)->get()
Fix: Add ->paginate(50) or ->limit(100)
SUMMARY
========
Issues found: 12
Critical (queries in loops): 3
High (missing indexes): 5
Medium (unbounded selects): 3
Low (SELECT * patterns): 1
In fix mode, generate migrations for missing indexes:
Schema::table('properties', function (Blueprint $table) {
$table->index('status');
$table->index('organization_id');
});
For queries-in-loops and unbounded selects, show the suggested refactoring code but do not auto-apply (risk of breaking logic). Present as recommendations with file path and line number.
EXPLAIN on actual queries for definitive performance analysis.$table->foreignId() automatically get indexes in MySQL via the FK constraint. These are safe.