Skip to content

[6.x] Look up the Comb index once when paginating search results - #15724

Open
edalzell wants to merge 1 commit into
statamic:6.xfrom
edalzell:fix/comb-lookup-runs-twice-when-paginating
Open

edalzell wants to merge 1 commit into
statamic:6.xfrom
edalzell:fix/comb-lookup-runs-twice-when-paginating

Conversation

@edalzell

@edalzell edalzell commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Builder::paginate() calls getCountForPagination() for the total and then get() for the page. On the local driver both end up in Comb\Query::getSearchResults(), which calls index->lookup() each time, so {{ search:results paginate="10" }} (or Search::index('default')->search('foo')->paginate(10)) decodes the index file and runs the full Comb scan twice per request.

Fix memoizes the lookup per query builder instance, keyed by the query string, in Comb\Query only. Tests: paginate() calls lookup() once; changing the query via query() looks up again.

Benchmark (synthetic local index, withoutData(), median ms over 5 runs, PHP 8.5, M-series Mac; script: https://gist.github.com/edalzell/4d75387d098abbebf63f00c523db8d18):

docs query paginate(10) before paginate(10) after get() before get() after
1,000 common 65.6 29.1 30.7 43.3
1,000 rareword 64.0 31.9 31.7 31.3
5,000 common 308.5 148.6 164.6 147.7
5,000 rareword 335.1 158.5 167.0 158.2
10,000 common 617.7 305.5 324.4 304.5
10,000 rareword 649.0 322.4 329.7 324.5

The 1,000/common get() row is the first measurement of the run (opcache cold); every other row shows get() unchanged.

The same double call affects Search\QueryBuilder::getBaseItems() for every driver (hydration runs twice, Algolia makes two API calls); left for a follow-up since #13217 is changing that area.

This branch has not been deployed

No deployments
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.

1 participant