PHPackages                             mention/fast-doctrine-paginator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. mention/fast-doctrine-paginator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mention/fast-doctrine-paginator
===============================

Fast Doctrine paginator for batching, infinite scrolling, Relay

2.0.0(2y ago)18126.9k↓48.4%1MITPHPCI failing

Since Dec 6Pushed 2y ago5 watchersCompare

[ Source](https://github.com/mentionapp/fast-doctrine-paginator)[ Packagist](https://packagist.org/packages/mention/fast-doctrine-paginator)[ RSS](/packages/mention-fast-doctrine-paginator/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (1)Dependencies (17)Versions (2)Used By (0)

Fast Doctrine Paginator
=======================

[](#fast-doctrine-paginator)

This package provides a fast, no-offset, Doctrine paginator that's suitable for infinite scrolling, batch jobs, and GraphQL/Relay pagination.

[![Build Status](https://camo.githubusercontent.com/7da1acdee340fce79ee2f4eff0851029f2fc1c8abc158a8d29c37c0dac3d1196/68747470733a2f2f7472617669732d63692e6f72672f6d656e74696f6e6170702f666173742d646f637472696e652d706167696e61746f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/mentionapp/fast-doctrine-paginator)[![Latest Version](https://camo.githubusercontent.com/823ef8d54beaffa113023ec344cc3e6a3cdf9234c018201f260db1283c160583/68747470733a2f2f706f7365722e707567782e6f72672f6d656e74696f6e2f666173742d646f637472696e652d706167696e61746f722f762f737461626c653f5f)](https://packagist.org/packages/mention/fast-doctrine-paginator)[![MIT License](https://camo.githubusercontent.com/fcdb38a63199892ed7b54f53d8b488dfa023a928be63fb97bc9895b11410c1cd/68747470733a2f2f706f7365722e707567782e6f72672f6d656e74696f6e2f666173742d646f637472696e652d706167696e61746f722f6c6963656e73653f5f)](https://choosealicense.com/licenses/mit/)[![PHPStan Enabled](https://camo.githubusercontent.com/441b5874ce4df0a2defc892979c96c46889b69cb32119d04f0b48626349f8bc9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d656e61626c65642d627269676874677265656e2e7376673f7374796c653d666c6174)](https://github.com/phpstan/phpstan)

Install
-------

[](#install)

```
composer require mention/fast-doctrine-paginator

```

Why use this paginator ?
------------------------

[](#why-use-this-paginator-)

### It is fast

[](#it-is-fast)

What makes this paginator fast is that it relies on seek/keyset pagination rather than limit/offset. Learn more at .

In addition to that, it lets the user write its own optimised queries.

### It is suitable for batch jobs

[](#it-is-suitable-for-batch-jobs)

Batch jobs over Doctrine queries typically have two problems:

- The query returns too many results at once and exhausts the memory (even when using `iterate()`, because the query result is still buffered locally)
- The entities accumulate in the UnitOfWork and exhaust the memory

Using this paginator solves these two problems:

- By using a paginated query, we avoid fetching too many items at once
- By giving the opportunity to act before and after each page, the paginator gives a safe point where the entity manager can be cleared, in order to keep the number of managed entities under control

### It is suitable for GraphQL/Relay

[](#it-is-suitable-for-graphqlrelay)

GraphQL/Relay style pagination requires fine-grained cursors that point to the beginning and end of a page, as well as to each item in a page. This paginator provides that.

### It is suitable for infinite scrolling

[](#it-is-suitable-for-infinite-scrolling)

Every page will be as fast as the previous one.

### It is type safe

[](#it-is-type-safe)

The paginator is fully typed and supports [phpstan-doctrine](https://github.com/phpstan/phpstan-doctrine)'s static type inference of query results.

When *not* to use this paginator ?
----------------------------------

[](#when-not-to-use-this-paginator-)

This paginator is cursor-based, so it may not be suitable for you if you need to access a page by number (although this could be emulated).

Usage
-----

[](#usage)

Here is a typical example:

```
