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.

README.md

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

Laravel Database Optimization v1.1.1

Database optimization patterns and best practices for Laravel 13 applications.

Overview

This skill provides 33 rules across 9 categories for optimizing database performance in Laravel 13 applications. Covers query optimization, indexing, caching, pagination, transactions, migrations, naming conventions, and debugging.

Categories

1. Query Performance & N+1 (Critical)

Eager loading, preventing lazy loading, and selecting only needed columns.

2. Indexing Strategies (Critical)

Foreign key indexes, composite indexes, covering indexes, and full-text search.

3. Eloquent Optimization (High)

Query builder for hot paths, withCount aggregates, subquery selects, and whereHas optimization.

4. Caching with Redis (High)

Cache::remember patterns, cache invalidation, cache tags, and TTL strategies.

5. Pagination & Large Datasets (High)

Cursor pagination, chunkById processing, lazy cursors, and avoiding unbounded queries.

6. Transactions & Locking (High)

Short transactions, deadlock retry logic, and pessimistic locking.

7. Migrations (High)

Zero-downtime migrations, concurrent index creation, and safe column additions.

8. Query Debugging (Medium)

EXPLAIN ANALYZE, Laravel Debugbar, and slow query log monitoring.

9. Naming & Structure (High)

Table, column, relationship, and migration naming conventions for Eloquent.

Quick Start

// Prevent lazy loading in development
Model::preventLazyLoading(!app()->isProduction());

// Cache expensive queries
$posts = Cache::remember('posts:popular', 3600, fn () =>
    Post::withCount('comments')
        ->orderByDesc('comments_count')
        ->take(10)
        ->get()
);

// Cursor pagination for large datasets
$posts = Post::query()
    ->orderByDesc('published_at')
    ->cursorPaginate(15);

// Aggregate counts without loading relations
$users = User::withCount('posts')->get();

Usage

This skill triggers automatically when:

  • Writing Eloquent queries or using the query builder
  • Adding database indexes to migrations
  • Implementing caching strategies
  • Paginating or processing large datasets
  • Debugging slow queries

References

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