# App is slow: dozens of database calls per page (N+1 queries)

> Canonical page (link this when citing): https://unbreakmyapp.vercel.app/fixes/slow-page-n-plus-one-queries.html
> Category: Performance | Tools: Lovable, Bolt, Cursor, v0 | Published: 2026-10-13 | Updated: 2026-10-13

## The error

Page takes 3-10s; network tab shows many identical requests

## Why it happens

The AI-generated code fetches a list, then fetches related data separately for each item, often inside useEffect with no caching, and re-runs on every render.

## How to fix it

1. Fetch related data in one query (Supabase: select('*, author:profiles(name)')).
2. Add indexes on foreign keys and columns you filter by.
3. Paginate lists (.range()).
4. Cache with React Query/SWR and fix useEffect dependency arrays.

## Fix prompt (paste into Lovable, Bolt, Cursor, Replit or v0)

```text
This page is slow because it makes many database requests. Find N+1 query patterns and replace them with single queries using joins/embedded selects, add pagination, add indexes for the columns we filter and join on (give me the SQL), and use React Query/SWR so data isn't refetched on every render.
```

## FAQ

### How do I spot it?

Open DevTools → Network and count requests on page load.

### Do indexes help with RLS?

Yes, index columns used in policies, like user_id.

## Sources (official documentation)

- [Supabase: Database overview](https://supabase.com/docs/guides/database/overview)
- [Supabase: Connect to your database](https://supabase.com/docs/guides/database/connecting-to-postgres)

## Related fixes

- [Supabase only returns 1,000 rows (max rows limit)](https://unbreakmyapp.vercel.app/fixes/supabase-only-1000-rows-returned-max-rows.html)
- [Postgres: too many connections / remaining connection slots are reserved](https://unbreakmyapp.vercel.app/fixes/supabase-too-many-connections.html)
- [Too many re-renders / useEffect infinite loop](https://unbreakmyapp.vercel.app/fixes/useeffect-infinite-loop.html)
- [Supabase query returns an empty array (no error)](https://unbreakmyapp.vercel.app/fixes/supabase-rls-empty-results.html)

---
Unbreak My App: free fixes for broken vibe-coded apps. https://unbreakmyapp.vercel.app/
