All skills
asyrafhussin avatar

/laravel-database-optimization

@ac26821

Laravel database optimization patterns. Use when writing Eloquent queries, creating migrations, configuring caching, debugging slow queries, or optimizing database performance. Triggers on tasks involving N+1 queries, indexing, Redis caching, pagination, or database transactions.

Use this Skill: https://skilld.dev/gh/asyrafhussin/agent-skills/laravel-database-optimization

This session only. Nothing lands on disk.

rulesdebug-laravel-debugbar.md

≈700 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Install Debugbar in Development

Impact: MEDIUM (Surfaces N+1 queries, duplicate queries, and slow queries automatically during development)

Without query monitoring, N+1 problems and duplicate queries silently accumulate during development. Debugbar displays query count, execution time, memory usage, and duplicate queries on every page load, making performance regressions immediately visible before they reach production.

Incorrect

// ❌ No query monitoring — performance issues go unnoticed during development
// A page fires 200 queries and takes 800ms but looks fine to the developer
// N+1 problems only surface when production load exposes the slowdown
// Duplicate queries waste database resources but are invisible without tooling

// Common scenario:
// - Developer adds a relationship accessor in a Blade template
// - Page still loads in 200ms locally with 50 test records
// - In production with 10,000 records, the page takes 15 seconds
// - No one notices until users complain

Problems:

  • N+1 queries are invisible during normal development — pages still load fast with small datasets
  • Duplicate queries from multiple components rendering the same data go undetected
  • Memory leaks from eager loading too much data are only caught in production

Correct

# ✅ Install as a dev-only dependency
composer require barryvdh/laravel-debugbar --dev
// ✅ Configure in .env — only enable in local/development
// DEBUGBAR_ENABLED=true

// ✅ Debugbar automatically shows on every page:
// - Queries tab: total count, time per query, duplicate detection
// - Timeline tab: request lifecycle breakdown
// - Memory tab: peak memory usage
// - Models tab: number of Eloquent models hydrated

// ✅ Programmatic usage for API debugging
use Barryvdh\Debugbar\Facades\Debugbar;

Debugbar::startMeasure('api-call', 'External API Call');
$response = Http::get('https://api.example.com/data');
Debugbar::stopMeasure('api-call');

// ✅ Disable in production — ensure it's in require-dev, not require
// config/debugbar.php
return [
    'enabled' => env('DEBUGBAR_ENABLED', false),
    'storage' => [
        'enabled' => false, // Don't store debugbar data in production
    ],
];

Benefits:

  • Instant visibility into query count and execution time on every page load
  • Highlights duplicate queries automatically — easy to spot missing eager loads
  • Dev-only dependency with zero production overhead when properly configured

Reference: Laravel Debugbar

Source: SKILL.md on GitHub

1 warning16d5 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    This skill is a comprehensive documentation set for optimizing database performance in Laravel 13 applications. It provides best practices for Eloquent queries, indexing, Redis caching, and safe migrations. No malicious patterns, prompt injections, or data exfiltration attempts were detected.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer6mo

    6/39 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at ac26821. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Steadyupdated 7 months ago
metadata
{
  "author": "agent-skills",
  "version": "1.1.1"
}

README badge

README badge for asyrafhussin/agent-skills/laravel-database-optimization