agentleFS
soden46soden46/syarif-laravel-ai-skills/skills/laravel-database-optimization/SKILL.md

laravel-database-optimization

Skill4 starsChanged 5 months agoMITView on GitHub

Optimize Laravel database work across N+1 queries, indexes, selective columns, caching, pagination, large data, locks, and migrations.

The file

Show its rules and text

We split this skill into the rules it gives an agent

13 rules. About 0 are common, 11 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈11

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill when improving query performance, reviewing migrations, debugging slow pages, or reducing memory and database load in …

    line 11
  2. Distinctive:

    Add indexes that match actual filters, joins, sorts, and uniqueness rules.

    line 19
  3. Very specific:

    Use withCount, withSum, exists, subqueries, or aggregates instead of loading full relations for summaries.

    line 28
  4. Very specific:

    Avoid unbounded all(), broad get(), and collection-side filtering on large tables.

    line 29
  5. Distinctive:

    Use cursor pagination or chunking for large ordered datasets and background processing.

    line 30
  6. Distinctive:

    Add indexes for foreign keys, common filters, common sort paths, and composite access patterns.

    line 34
  7. Distinctive:

    Avoid adding indexes speculatively without a query path that needs them.

    line 36
  8. Distinctive:

    When altering existing columns, preserve existing attributes required by the database platform.

    line 38
  9. Distinctive:

    Use tags only when the configured cache store supports them.

    line 44
  10. Distinctive:

    Do not cache user-specific or authorization-sensitive data without including the scope in the key.

    line 45
  11. Distinctive:

    Keep transactions short and free of slow external calls.

    line 49
  12. Distinctive:

    Use row locks only around data that must remain consistent during the write.

    line 50
  13. Distinctive:

    Use retry logic for known deadlock-prone flows.

    line 51

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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

  1. Prove the bottleneck with logs, query inspection, profiling, EXPLAIN, tests, or realistic data volume.
  2. Fix query shape before adding infrastructure: eager loading, constraints, selective columns, aggregates, pagination, and bounded datasets.
  3. Add indexes that match actual filters, joins, sorts, and uniqueness rules.
  4. Cache only stable or expensive work with explicit invalidation.
  5. Review transaction scope, lock behavior, and retry strategy for write-heavy paths.
  6. 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(), broad get(), 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-loading
  • performance-select-columns
  • performance-caching
  • data-chunking-large-datasets
  • migrations-and-factories
  • database-transactions

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.