Skip to content

Add OffsetPaginator::count() to get the total without fetching rows - #12657

Open
seb-jean wants to merge 1 commit into
doctrine:3.8.xfrom
seb-jean:offset-paginator-count
Open

seb-jean wants to merge 1 commit into
doctrine:3.8.xfrom
seb-jean:offset-paginator-count

Conversation

@seb-jean

@seb-jean seb-jean commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #12636

Counterpart of #12627: adds a way to get the count without fetching rows.

$total = (new OffsetPaginator(fetchJoinCollection: true))->count($query);

count() runs the same COUNT query as WindowPage::getTotalCount(), and nothing else.

OffsetPaginator::paginate() always fetches a window of rows, so getting
the total alone meant paginating and discarding the items. The legacy
Paginator::count() was the only count-only entry point, and it is
deprecated.

count() runs the same COUNT query as WindowPage::getTotalCount(), and
nothing else, which covers pagination adapters that separate counting
from slicing, clamping a requested page number, or totals displayed
without a listing.

Fixes doctrine#12636
@seb-jean
seb-jean force-pushed the offset-paginator-count branch from 308484d to d0ef854 Compare October 7, 2026 10:03
@seb-jean

seb-jean commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

cc @hlecorche

never affects a page you already hold.

When only the total is needed — to clamp a requested page number before
fetching it, to display a "N results" badge, or to cache the total separately

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fetching it, to display a "N results" badge, or to cache the total separately
fetching it, to display an "N results" badge, or to cache the total separately


When only the total is needed — to clamp a requested page number before
fetching it, to display a "N results" badge, or to cache the total separately
from the pages — ``count()`` runs the ``COUNT`` query alone, without fetching

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could count end up being ambiguous? Is there a possibility that we add a method that allows to count pages in the future? If yes name this one getTotalCount, and the other getPageCount() or something like that?

@hlecorche

Copy link
Copy Markdown

I ported my paginator to it on this branch: count() is a drop-in for Paginator::count() (same COUNT query, useOutputWalkers honoured, NoResultException → 0), tests green and no extra query.
Thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants