Repository navigation
[6.x] Work the pattern for a like where out once - #15895
Merged
jasonvarga merged 3 commits intoNov 13, 2026
Merged
Conversation
…tern # Conflicts: # tests/Data/Entries/EntryQueryBuilderTest.php
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.
A
likewhere works out the same regular expression again for every item it's tested against.filterTestLike()turns the SQL-style pattern into a regex withPattern::sqlLikeToRegex()each time it's called, and it's called once per item. The pattern belongs to the where, so it's the same every time.It's now worked out the first time and remembered on the query builder, by the string being looked for. It's kept on the instance rather than statically, so a long-running worker doesn't collect every search anyone has made.
not likegoes through the same method, and a value that isn't a string is converted each time as before.This is the path behind
where('title', 'like', ...)in a Control Panel listing search when there's no search index, thecontains,starts_withandends_withconditions on tags, and user and form submission searches.Numbers
Converting the pattern for each of 2,000 items takes 6.7 ms; doing it once and matching 2,000 items takes 0.5 ms.
Queries on a collection of 2,000 entries, average of 20 runs:
where('title', 'like', '%amber%')orWherewhere('title', 'not like', '%a%')across every collectionEach finds the same entries as before.
Tests
The pattern is asked for once for a query that tests several entries (fails without the change), and a query with four different likes still applies each of them.