6
votes

I'm building an API and I would like to know what is the best way to paginate in symfony (v4) and doctrine ORM.

I've used some bundles such as knp paginator and Pagerfanta,but I'm asking because I'm concerned with performance when we have much data in the DB. would't be better to use Doctrine's Paginator and implements a pagination by myself ?

thanks.

1

1 Answers

14
votes

It's hard to answer if you didn't mention how much data you expect.

For now, I would simply use whiteoctober/Pagerfanta.

I use Pagerfanta to paginate results of ~200 000 000 records from single Postgres table.

There are no performance issues.

It is also used in official Symfony 4 demo.

Implementing your own, more efficient paginator - to me will always sound like a great idea (and challenge). But you won't be able to check it's efficiency without having expected amount of data.