Repository navigation
[6.x] Only look among the entries found so far when a query narrows them further - #15891
Closed
DanielDarrenJones wants to merge 2 commits into
Closed
DanielDarrenJones wants to merge 2 commits into
DanielDarrenJones wants to merge 2 commits into
Conversation
Member
|
Thanks for this but this one is adding complexity to gain maybe a few milliseconds. If you can show gains on a realistic site we can reconsider. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Once an entry query has narrowed down to a few entries, every
whereafter that still looks through the whole collection.The Stache entry query builder works each
whereout over the full index of every collection being queried, and then intersects the result with the keys it has so far. A relationship field is the common case:whereIn('id', [...])leaves a handful of entries, and thenpublished, the status conditions and oftensiteeach go through every entry in the collection to arrive at a subset of that handful.Now, when there are 250 keys or fewer so far and the next
whereis one whose result is intersected with them, a basic orwhereIncondition only tests the index values of those keys. That carries into nested wheres. AnorWhere, the other kinds of where, and larger sets of keys go the way they did. The keys that come back, and their order, are the same.The two protected methods involved keep their signatures, so a query builder that extends this one and overrides them isn't affected.
Numbers
One query over a collection of 2,000 entries, average of 50 runs:
whereIn('id', 170 ids)->where('published', true)->whereStatus('published')->whereStatus('published')->where('site', 'en')The time that's saved is in proportion to the size of the collection, so it's small on a site this size: of 35 pages and Control Panel requests timed, one (a localized page with several relationship fields) was faster, by 13% and 17% in two runs, and the rest were within noise. Every response was byte for byte the same.
Tests
A where after three entries have been found tests three values rather than the whole collection (fails without the change). Fourteen combinations of and, or, nested,
whereIn,whereNotIn, status, like and ordering after a narrowingwhereIngive the same results before and after.