Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

laravel-database-optimization

БесплатноБез исполняемых скриптовНе проверен

Laravel database optimization patterns. Use when writing Eloquent queries, creating migrations, configuring caching, debugging slow queries, or optimizing…

AsyrafHussinот AsyrafHussin★ 112 звёзд на GitHub

Об этом скилле

Laravel Database Optimization

Comprehensive database optimization guide for Laravel 13 applications. Contains 33 rules across 9 categories for writing performant database queries, proper indexing, efficient caching, naming conventions, and debugging slow queries in Laravel 13.

Metadata

  • Version: 1.2.0
  • Framework: Laravel 13.x (tested 13.43+)
  • Updated: November 2026
  • PHP: 8.3+

When to Apply

Reference these guidelines when:

  • Writing Eloquent queries or using the query builder
  • Diagnosing and fixing N+1 query problems
  • Adding database indexes to migrations
  • Implementing Redis or cache-based optimizations
  • Paginating or processing large datasets
  • Wrapping operations in database transactions
  • Creating or modifying migrations for production databases
  • Debugging slow queries with EXPLAIN or Laravel Debugbar

Rule Categories by Priority

Priority Category Impact Prefix
1 Query Performance & N+1 CRITICAL query-
2 Indexing Strategies CRITICAL index-
3 Eloquent Optimization HIGH eloquent-
4 Caching with Redis HIGH cache-
5 Pagination & Large Datasets HIGH data-
6 Transactions & Locking HIGH lock-
7 Migrations HIGH migrate-
8 Query Debugging MEDIUM debug-
9 Naming & Structure HIGH naming-

Quick Reference

1. Query Performance & N+1 (CRITICAL)

  • query-eager-loading - Use eager loading to eliminate N+1 queries
  • query-prevent-lazy-loading - Prevent lazy loading in development
  • query-auto-eager-loading - Configure automatic eager loading (Model::automaticallyEagerLoadRelationships(), Laravel 12.8+)
  • query-select-columns - Select only needed columns instead of SELECT *

2. Indexing Strategies (CRITICAL)

  • index-foreign-keys - Index all foreign key columns
  • index-composite-indexes - Create composite indexes for multi-column queries
  • index-covering-indexes - Use covering indexes for read-heavy queries
  • index-full-text - Use full-text indexes for search functionality

3. Eloquent Optimization (HIGH)

  • eloquent-query-builder-hot-paths - Use query builder for performance-critical paths
  • eloquent-with-count-aggregates - Use withCount instead of loading relations to count
  • eloquent-subquery-selects - Use subquery selects to avoid extra queries
  • eloquent-where-has-optimization - Optimize whereHas with whereIn subqueries

4. Caching with Redis (HIGH)

  • cache-remember - Use Cache::remember for expensive queries; Cache::flexible() or Cache::lock() for hot keys (remember() takes no lock)
  • cache-invalidation - Invalidate cache on model changes
  • cache-tags - Use cache tags for group invalidation (not on file, dynamodb, database or storage stores)
  • cache-ttl - Set appropriate TTL values for cached data

5. Pagination & Large Datasets (HIGH)

  • data-cursor-pagination - Use cursor pagination for large datasets
  • data-chunk-by-id - Process large datasets with chunkById
  • data-cursor-iteration - Use lazy cursors for memory-efficient iteration
  • data-avoid-unbounded - Never use unbounded queries on large tables

6. Transactions & Locking (HIGH)

  • lock-short-transactions - Keep transactions short and focused
  • lock-deadlock-retry - Implement deadlock retry logic
  • lock-pessimistic-locking - Use pessimistic locking for critical updates

7. Migrations (HIGH)

  • migrate-zero-downtime - Write zero-downtime migrations
  • migrate-concurrent-indexes - Create indexes without locking: ->online() (PostgreSQL/SQL Server), ->inplace()->lock('none') (MySQL, 13.33+)
  • migrate-safe-column-additions - Add columns safely without locking tables

8. Query Debugging (MEDIUM)

  • debug-explain-analyze - Use EXPLAIN ANALYZE to understand query plans
  • debug-laravel-debugbar - Use Laravel Debugbar to find query bottlenecks
  • debug-slow-query-log - Enable and monitor slow query logs

9. Naming & Structure (HIGH)

  • naming-tables - Table naming conventions (plural snake_case, pivot alphabetical)
  • naming-columns - Column naming conventions (FKs, booleans, timestamps, polymorphic)
  • naming-relationships - Relationship method naming (singular/plural matching)
  • naming-migrations - Migration and index naming conventions

Essential Patterns

Prevent Lazy Loading in Development

<?php

namespace App\Providers;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        Model::preventLazyLoading(!app()->isProduction());
    }
}

Cache Expensive Queries with Redis

<?php

use Illuminate\Support\Facades\Cache;

// Cache a query result for 1 hour (3600 seconds)
$popularPosts = Cache::remember('posts:popular', 3600, fn () =>
    Post::query()
        ->withCount('comments')
        ->orderByDesc('comment
Полный SKILL.md на GitHub

Установить laravel-database-optimization в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

AGENTS.mdREADME.mdmetadata.jsonrules/_sections.mdrules/_template.mdrules/cache-invalidation.mdrules/cache-remember.mdrules/cache-tags.mdrules/cache-ttl.mdrules/data-avoid-unbounded.mdrules/data-chunk-by-id.mdrules/data-cursor-iteration.mdrules/data-cursor-pagination.mdrules/debug-explain-analyze.mdrules/debug-laravel-debugbar.mdrules/debug-slow-query-log.mdrules/eloquent-query-builder-hot-paths.mdrules/eloquent-subquery-selects.mdrules/eloquent-where-has-optimization.mdrules/eloquent-with-count-aggregates.mdrules/index-composite-indexes.mdrules/index-covering-indexes.mdrules/index-foreign-keys.mdrules/index-full-text.mdrules/lock-deadlock-retry.mdrules/lock-pessimistic-locking.mdrules/lock-short-transactions.mdrules/migrate-concurrent-indexes.mdrules/migrate-safe-column-additions.mdrules/migrate-zero-downtime.mdrules/naming-columns.mdrules/naming-migrations.mdrules/naming-relationships.mdrules/naming-tables.mdrules/query-auto-eager-loading.mdrules/query-eager-loading.mdrules/query-prevent-lazy-loading.mdrules/query-select-columns.md

FAQ

Что делает скилл laravel-database-optimization?

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.

Как установить скилл laravel-database-optimization?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл laravel-database-optimization запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить laravel-database-optimization с