Laravel database optimization
Skill soden46/syarif-laravel-ai-skills/skills/laravel-database-optimization
Optimize Laravel database work across N+1 queries, indexes, selective columns, caching, pagination, large data, locks, and migrations.From its SKILL.md
npx -y skills add soden46/syarif-laravel-ai-skills --skill laravel-database-optimizationAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 3 stars3 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
2.7 KB, 503 tokens by cl100k_base, as published. Nobody here has run it
Laravel Database Optimization
Use this skill when improving query performance, reviewing migrations, debugging slow pages, or reducing memory and database load in Laravel apps.
This skill coordinates existing performance skills and adds an optimization workflow.
Priority Order
- Prove the bottleneck with logs, query inspection, profiling,
EXPLAIN, tests, or realistic data volume. - Fix query shape before adding infrastructure: eager loading, constraints, selective columns, aggregates, pagination, and bounded datasets.
- Add indexes that match actual filters, joins, sorts, and uniqueness rules.
- Cache only stable or expensive work with explicit invalidation.
- Review transaction scope, lock behavior, and retry strategy for write-heavy paths.
- Plan migrations with production data size and lock risk in mind.
Query Shape
- Prevent N+1 problems with intentional eager loading.
- Select only needed columns on hot paths, including constrained relationship columns.
- Use
withCount,withSum,exists, subqueries, or aggregates instead of loading full relations for summaries. - Avoid unbounded
all(), broadget(), and collection-side filtering on large tables. - Use cursor pagination or chunking for large ordered datasets and background processing.
Indexes And Migrations
- Add indexes for foreign keys, common filters, common sort paths, and composite access patterns.
- Match composite index order to the real query pattern.
- Avoid adding indexes speculatively without a query path that needs them.
- For production-scale tables, plan additive and reversible migrations; ask before destructive changes.
- When altering existing columns, preserve existing attributes required by the database platform.
Caching
- Cache expensive reads behind stable keys and short, intentional TTLs.
- Invalidate cache near the writes that change the underlying data.
- Use tags only when the configured cache store supports them.
- Do not cache user-specific or authorization-sensitive data without including the scope in the key.
Transactions And Locks
- Keep transactions short and free of slow external calls.
- Use row locks only around data that must remain consistent during the write.
- Use retry logic for known deadlock-prone flows.
- Dispatch jobs, events, notifications, and file cleanup after commit when correctness depends on committed data.
Related Skills
performance-eager-loadingperformance-select-columnsperformance-cachingdata-chunking-large-datasetsmigrations-and-factoriesdatabase-transactions
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.
Gives 0 of the 12 instructions most performance cost skills give in 503 tokens
Counted across 797 of the 1,117 authors here whose files we hold, read 2026-09-06
- Check for product marketing context firstin 46 of 797, across 20 files
- Measure before optimizingin 31 of 797, across 25 files
- Profile first to identify the actual bottleneckin 23 of 797, across 22 files
- Verify your robots.txt allows AI crawlersin 21 of 797, across 12 files
- Import directly and avoid barrel filesin 19 of 797, across 15 files
- Spawn all runs in the same turnin 18 of 797, across 11 files
- Write a draft of the skillin 17 of 797, across 10 files
- Understand the user's intentin 17 of 797, across 10 files
- Use React.cache for per-request deduplicationin 16 of 797, across 11 files
- Profile before optimizingin 16 of 797, across 14 files
- Include specific numbers with sourcesin 15 of 797, across 8 files
- Add lazy loading to below-fold imagesin 15 of 797, across 10 files
Said here and by no other author read
- Prove the bottleneck before fixing it
- Fix query shape before adding infrastructure
- Add indexes matching actual query filters
- Cache expensive reads with explicit invalidation
- Plan migrations with production data in mind
Grouped from the skills themselves: near-identical wordings counted once, and counted by distinct author, so one author publishing three of these counts once. Length counted with cl100k_base; the agent that loads this file may tokenize it differently.