Group
  • Database

    Add pagination to every list endpoint

    Replaces unbounded fetch-everything queries with cursor or offset pagination before tables get big.

    • Improve quality
    • Plan & validate
    • Beginner
    • General

Free Prompt

Find every place my app loads a list of records without a limit: admin tables, feed pages, search results, API list endpoints, export queries. Add pagination to each one. Choose the right pattern per case: cursor-based pagination (WHERE id > last_seen_id or a created_at cursor) for feeds and anything where data changes while paging, since offsets skip and duplicate rows when items are inserted mid-scroll; offset pagination for stable admin tables where page numbers are the UX; and a hard maximum page size on every API endpoint so clients can't request limit=1000000. Order every paginated query by a stable, indexed column with a tiebreaker, since pagination over a non-deterministic sort returns garbage. Do not change the UI design; if a page currently renders everything, keep 'load more' or infinite scroll patterns working against the paginated API. Do not paginate lookups that are inherently bounded (a user's own notification count). Deliver: a list of every endpoint fixed, the pattern used and why, the max page size enforced, and verification: request page 2 and confirm no overlap with page 1, then request an absurd limit and confirm it's capped.

What This Does / How This Helps

Puts real pagination on every list query in the app, with the pattern (cursor vs offset) matched to how the data behaves. SELECT everything works until it doesn't. With real data, unbounded queries get slower every day, then one day an endpoint fetching 40,000 rows takes down the page and the database connection with it. This always happens after launch, never before, because dev databases are tiny. The cursor-versus-offset distinction is the detail that keeps it working: offsets over a changing feed skip and repeat items as new rows arrive, which is why feeds get cursors and admin tables get page numbers.

Want to skip doing this by hand?

Fortivibe audits your app for all of the areas these prompts cover (and more).

See What We Check

Related Prompts