App is slow: dozens of database calls per page (N+1 queries)
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
- Fetch related data in one query (Supabase: select('*, author:profiles(name)')).
- Add indexes on foreign keys and columns you filter by.
- Paginate lists (.range()).
- Cache with React Query/SWR and fix useEffect dependency arrays.
Fix prompt (paste into Lovable, Bolt, Cursor, Replit or v0)
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.
Related fixes
- Postgres: too many connections / remaining connection slots are reserved
- Too many re-renders / useEffect infinite loop
- Supabase query returns an empty array (no error)
- new row violates row-level security policy for table
Want the full checklist for this area? Get a Fix Kit ($29)
Featured slot available: reach thousands of vibe coders. Sponsor this week →
Get one new fix a week
Free newsletter: the newest breakages in Lovable, Bolt, Cursor, Replit and v0 apps, with paste-in fixes.
We only use your email to send the newsletter. Unsubscribe any time. See privacy.