Cache filter URLs with more than one value - #167
Merged
Conversation
The page cache keyed query args already, but its value charset had no comma and a bracketed name could never be one. So `?genre=rock,jazz` — the format query-filters.md documents — and `?genre[]=rock&genre[]=jazz` both bypassed, and the framework's own filter URLs were the one shape its own cache refused. Let a comma through the floor, and join the bracketed form in request order to the key the comma form produces. nginx keeps the fast path for the comma form and declines the bracketed one, where declining means passing it to PHP: the drop-in serves the same file a couple of milliseconds later. Neither reader ever computes a key the other disagrees with, which stays the property that matters. Derive the keyed args from QueryFiltersConfig, so a declared filter cannot be an undeclared cache bypass, and take the pattern from its allowlist so the two agree on what a valid value is. Search joins the same mechanism: naming `s` in cacheQueryArgs is the opt-in, and the pattern is what bounds the key space. Co-authored-by: Claude <claude@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #167 +/- ##
============================================
+ Coverage 85.55% 85.66% +0.10%
- Complexity 2510 2535 +25
============================================
Files 194 194
Lines 6938 6988 +50
============================================
+ Hits 5936 5986 +50
Misses 1002 1002
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The page cache read QueryFiltersConfig to derive its keyed args, which put a `require` of one config file inside another and tied two concerns that have no reason to know each other. Drop it. cacheQueryArgs takes a list of allowed values instead of a pattern, so a project states what it knows — the page sizes, the languages — and the pattern is compiled from that. Naming a filter for the cache is now its own step, in the file that owns caching. Co-authored-by: Claude <claude@anthropic.com>
The filename pattern spelled the value charset a second time, so adding the comma for multi-value filters left it refusing `index__genre=rock,jazz&`. Every filtered request bypassed, with a reason that said `path` — a message about the URL, for a filename this cache would not write. Only the end-to-end suite caught it: the unit tests covered QueryKey and never CacheKey. Derive the pattern from the charset so the two cannot drift again, and cover the filename at the level the gap was in. Co-authored-by: Claude <claude@anthropic.com>
This was referenced Aug 28, 2026
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.
Closes the gap
.planning/research_facets.md(#166) identified as the blocker: the page cache keyed query args already, but not the shape a filter actually emits.What was broken
cacheQueryArgsworks and is proven end to end —?lang=fris served from nginx today. ButQueryKey::VALUE_CHARACTER_CLASShad no comma, and a bracketed name can never match the keyed-name pattern. So both spellings of a multi-value filter bypassed:?genre=rock,jazz?genre[]=rock&genre[]=jazz?s=chaisesis keyed with a pattern?genre=rock,jazzis the formatdocs/guide/query-filters.mddocuments, so the framework's own filter URLs were the one shape its own page cache refused to store.How the bracketed form is handled
nginx cannot read it — a variable name may not hold brackets, and there is no
$arg_genre[]. Rather than teach it to guess, it declines: a bracketed name failsknownQueryPattern(), so the request goes to PHP, and the drop-in joins the members and serves the file the comma form wrote. A couple of milliseconds slower, same bytes, no second file.What never happens is nginx reading
$arg_genre, finding it empty and serving the unfiltered page to someone who asked for a filtered one. That property — the two readers never compute keys that disagree — is what every rule inQueryKeyexists for, and it is unchanged.Members are joined in request order and never sorted. Sorting is the obvious fix and the wrong one: nginx cannot sort, so a sorted key is one only PHP could compute. Two orders are two files holding the same HTML — wasted disk, which is the cheap half of the trade.
A member may not contain a comma.
?genre[]=rock,jazzasks for one term whose slug has a comma;?genre=rock,jazzasks for two. Joining the first would key it where the second lives, so it bypasses.Values instead of patterns
cacheQueryArgs: [ 'page', // any value the charset allows 'lang' => ['fr', 'en'], // only these two 'posts_per_page' => [12, 24, 48], 'genre' => '^[a-z0-9-]+(?:,[a-z0-9-]+)*$', // a pattern, when a list will not do ],A project states what it knows and the pattern is compiled from it. Values are quoted, so
1.5matches1.5and not165. An empty list matches nothing — "these values are allowed" with none named is a bypass, not a free pass.The page cache config and the query filters config stay independent: neither reads the other, and there is no
requireof one config file inside another. Naming a filter for the cache is its own step, in the file that owns caching. The cost is stated in both guides — a filter added later is a bypass until it is named here.Search, by parameter
sbypasses unless it is keyed, and keying it means giving the pattern that bounds it. No new flag — it is the mechanism that already existed.Verification
composer lintclean of anything new;composer analysereports no issues.%5B%5D, derivation and precedence, and search.packages/starter/tests/smoke/NginxKeyedQueryTest.phpgains the two cases that matter, because only a real nginx can settle a claim about two implementations of one algorithm: the comma form must beHIT/nginx, and the bracketed form must beHIT/phpout of the same single file.🤖 Generated with Claude Code
https://claude.ai/code/session_01KZusb9DU8coizq3CDgHEqi