| name | name-laravel-supabase-db-optimization |
| description | "--- |
Laravel + Supabase Database Optimization
Purpose
Use this skill when the app is a Laravel project connected to Supabase/PostgreSQL and requests feel slow, especially if the delay appears to come from database access, Eloquent queries, or network latency.
Goal
Find the most likely cause of slowness, then produce specific fixes that reduce total request time.
What to check first
- Determine whether the delay is caused by:
- too many queries
- slow individual queries
- N+1 loading
- missing indexes
- heavy joins or filters
- overfetching
- connection/latency issues between Laravel and Supabase
- expensive model accessors, casts, or relationship loading
- Inspect the controller, model, migration, and query code before suggesting changes.
- Prefer evidence over guesswork. Identify the exact query or code path causing the delay.
Diagnostic workflow
1) Measure the problem
- Look for slow endpoints, repeated queries, and the number of SQL statements per request.
- Compare query time versus total request time.
- Separate database latency from application overhead.
2) Check for query inefficiency
- Look for N+1 queries in loops.
- Look for
select * when only a few columns are needed.
- Look for missing pagination on large result sets.
- Look for unnecessary relationship loading.
- Look for repeated queries for the same data.
3) Check the schema
- Verify indexes exist for:
- foreign keys
- frequent
where filters
order by columns
- join columns
- unique lookup columns like email, slug, or code
- Suggest composite indexes when multiple columns are commonly filtered together.
- Check whether column types and constraints match the query patterns.
4) Check Laravel patterns
- Prefer eager loading where appropriate.
- Prefer query builder or selective columns when Eloquent hydration is unnecessary.
- Recommend caching for data that changes infrequently.
- Suggest chunking or cursor pagination for large datasets.
- Avoid expensive repeated work inside loops.
5) Check Supabase/PostgreSQL connectivity
- Consider region/network latency between the Laravel host and Supabase project.
- Confirm the app uses the appropriate Supabase connection method for the environment.
- If relevant, distinguish between direct connections and pooled connections.
- Consider that remote database access can add noticeable latency even when queries are otherwise acceptable.
Output format
Always respond in this order:
- Most likely root cause
- Evidence from the code/query pattern
- Exact fixes
- Indexes to add
- Laravel code changes
- Supabase/PostgreSQL connection notes
- Priority order
- fastest fix first
- highest impact first
Quality rules
- Be specific.
- Do not give generic advice only.
- Show example code when useful.
- Show example SQL when suggesting indexes.
- Explain why each fix helps.
- If the problem is ambiguous, list the most likely causes in order of probability.
Suggested commands when useful
- Inspect migrations
- Inspect controllers
- Inspect models and relationships
- Inspect query logs
- Inspect routes and middleware
- Inspect
.env and config/database.php
- Inspect Supabase connection setup
Example response style
- "This looks like an N+1 query issue caused by loading relationships inside a loop."
- "Add an index on
user_id because it is used in where and join clauses."
- "Use eager loading and select only the columns needed."
- "The 3-second delay is likely a combination of network latency and repeated queries.""
Name Laravel Supabase Db Optimization
Overview
name: laravel-supabase-db-optimization
description: Diagnose and optimize slow Laravel + Supabase/PostgreSQL database requests, especially when response times are around 3 seconds or higher.
Laravel + Supabase Database Optimization
Purpose
Use this skill when the app is a Laravel project connected to Supabase/PostgreSQL and requests feel slow, especially if the delay appears to come from database access, Eloquent queries, or network latency.
Goal
Find the most likely cause of slowness, then produce specific fixes that reduce total request time.
What to check first
- Determine whether the delay is caused by:
- too many queries
- slow individual queries
- N+1 loading
- missing indexes
- heavy joins or filters
- overfetching
- connection/latency issues between Laravel and Supabase
- expensive model accessors, casts, or relationship loading
- Inspect the controller, model, migration, and query code before suggesting changes.
- Prefer evidence over guesswork. Identify the exact query or code path causing the delay.
Diagnostic workflow
1) Measure the problem
- Look for slow endpoints, repeated queries, and the number of SQL statements per request.
- Compare query time versus total request time.
- Separate database latency from application overhead.
2) Check for query inefficiency
- Look for N+1 queries in loops.
- Look for
select * when only a few columns are needed.
- Look for missing pagination on large result sets.
- Look for unnecessary relationship loading.
- Look for repeated queries for the same data.
3) Check the schema
- Verify indexes exist for:
- foreign keys
- frequent
where filters
order by columns
- join columns
- unique lookup columns like email, slug, or code
- Suggest composite indexes when multiple columns are commonly filtered together.
- Check whether column types and constraints match the query patterns.
4) Check Laravel patterns
- Prefer eager loading where appropriate.
- Prefer query builder or selective columns when Eloquent hydration is unnecessary.
- Recommend caching for data that changes infrequently.
- Suggest chunking or cursor pagination for large datasets.
- Avoid expensive repeated work inside loops.
5) Check Supabase/PostgreSQL connectivity
- Consider region/network latency between the Laravel host and Supabase project.
- Confirm the app uses the appropriate Supabase connection method for the environment.
- If relevant, distinguish between direct connections and pooled connections.
- Consider that remote database access can add noticeable latency even when queries are otherwise acceptable.
Output format
Always respond in this order:
- Most likely root cause
- Evidence from the code/query pattern
- Exact fixes
- Indexes to add
- Laravel code changes
- Supabase/PostgreSQL connection notes
- Priority order
- fastest fix first
- highest impact first
Quality rules
- Be specific.
- Do not give generic advice only.
- Show example code when useful.
- Show example SQL when suggesting indexes.
- Explain why each fix helps.
- If the problem is ambiguous, list the most likely causes in order of probability.
Suggested commands when useful
- Inspect migrations
- Inspect controllers
- Inspect models and relationships
- Inspect query logs
- Inspect routes and middleware
- Inspect
.env and config/database.php
- Inspect Supabase connection setup
Example response style
- "This looks like an N+1 query issue caused by loading relationships inside a loop."
- "Add an index on
user_id because it is used in where and join clauses."
- "Use eager loading and select only the columns needed."
- "The 3-second delay is likely a combination of network latency and repeated queries."
When to Use
Use this skill when:
- [Describe trigger scenarios]
Instructions
[Add step-by-step instructions here]