Skip to content

Conversation

@willtj
Copy link

@willtj willtj commented Dec 14, 2023

I've known for a while that when paginating in ES we end up making two queries - one for the results and another with a limit of 1 for the count.

Laravel's base class has a 'getCountForPagination' method that would do this in SQL, which this library overrides. That method tries to only re-run the query if $this->results is null but because of the way Laravel creates a new query when it applies scopes, that value is always null when checking here.

We can always rely on the raw results being available here so this is a much more efficient method.

@willtj willtj requested a review from danjohnson95 December 14, 2023 13:09
Copy link
Member

@danjohnson95 danjohnson95 left a comment

Choose a reason for hiding this comment

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

Really really nice change, ty!

@willtj willtj merged commit e2e6829 into master Dec 14, 2023
@willtj willtj deleted the pagination-count branch December 14, 2023 13:42
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.

2 participants