Repository navigation
Fix #255: query-variant cache entries survive a bare-URI purge #256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
157e773
Fix #255: query-variant cache entries survive a bare-URI purge
koriym 1fe3559
Fix PHPMD ExcessiveClassComplexity in DonutRepository (CI)
koriym 09f8358
Mark BaseUriTagInterface/BaseUriTag @internal; shrink SurrogateKeys API
koriym 751b4a6
Align @internal placement with MatchQueryInterface/MatchQuery precedent
koriym b0cae9c
Address CodeRabbit review: auto-purge coarsening, consistent default …
koriym d813e72
Close patch-coverage gap: cover baseQuery's required-param branch
koriym f3a1236
Document the auto-purge coarsening behavior change in CHANGELOG
koriym fe600dd
Trim diary-style comments to plain statements of fact
koriym 5cb1b94
Drop remaining history/reviewer framing from two comments
koriym 5361371
Fix blocker: bare-URI self-cleanup was evicting every sibling variant
koriym 552bd7d
Update DonutCacheInterceptorTest for the group tag save_donut now rec…
koriym 2cbc6a9
Document the bare-URI self-cleanup blocker fix in the changelog
koriym 6ad533b
Fix second blocker: donut refresh dropped the group tag from the ETag…
koriym ef1cba9
Close a test-coverage gap Kimi K3.1 Pro found: initial donut save's E…
koriym f3af963
Close the same test-coverage gap for the dynamic #[DonutCache] flavor
koriym a2b80f3
Trim narrating comments to statements of fact
koriym 9523135
State what BaseUriTag is instead of why it was added
koriym ea7a631
Say what the default BaseUriTag is in the constructors
koriym 3905aef
Shorten the saveEtag() comment to a statement of fact
koriym a95fab6
Make BaseUriTagInterface a required constructor dependency
koriym 85eecb0
Keep query variants cached when the bare URI answers an error
koriym 1036de6
Pin the error path's own-tag invalidation in its test
koriym 17da888
CHANGELOG: a purge URI that spells out a default value is not coarsened
koriym 47eaf0f
CHANGELOG: describe the auto-purge with real write targets, not edits…
koriym 562d82a
Mark BaseUriTagInterface @internal as BaseUriTag is
koriym dfafd0b
Reach a parent that embeds a query variant, and keep snake_case keys …
koriym 3ba6b59
Reach a page that renders a query variant as a hole
koriym e1be240
Do not restore an injector serialized by 1.18.0
koriym 0c189ba
Pin that a camelCase required key stays camelCase in the group tag
koriym b6656ac
CHANGELOG: a parent's CDN Surrogate-Key header carries the child's gr…
koriym b79616f
CHANGELOG: require a new CacheVersionModule version, list ResourceSto…
koriym ccf988b
CHANGELOG: narrow the old-template claim, state the snake_case auto-p…
koriym d562e39
Pin the static donut's own group tag for a custom UriTag
koriym 68cd7d7
Match the custom tag exactly; narrow what a bare purge misses on old …
koriym ccd4a87
Match the dynamic donut's group tag as a whole token
koriym d9a0a40
CHANGELOG: a purge URI must spell each required key the way the GET did
koriym 36da94e
CHANGELOG: scope the spelling constraint to a purge aimed at the GET …
koriym 9482206
Lead the changelog with the deploy steps; document query-variant purges
koriym 55fdc7d
Docs: a #[DonutCache] write purges only with #[RefreshCache]; purger …
koriym File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace BEAR\QueryRepository; | ||
|
|
||
| use BEAR\Resource\ResourceObject; | ||
| use Override; | ||
| use ReflectionMethod; | ||
|
|
||
| use function ltrim; | ||
| use function method_exists; | ||
| use function preg_replace; | ||
| use function strtolower; | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| * | ||
| * @internal | ||
| * | ||
| * Drops every default-valued onGet() parameter, supplied or not (MatchQuery keeps the supplied ones); | ||
| * required parameters stay: `onGet(int $userId, int $page = 1)` maps `?userId=1&page=2` to `?userId=1`. | ||
| * A required parameter keeps the key the request spelled, `userId` or the `user_id` BEAR.Resource also binds. | ||
| */ | ||
| final class BaseUriTag implements BaseUriTagInterface | ||
| { | ||
| /** | ||
| * Keeps the group tag distinct from a resource's own UriTag, which cleanUpBeforeWrite() invalidates. | ||
| * | ||
| * @see QueryRepository::GROUP_TAG_PREFIX | ||
| */ | ||
| private const GROUP_TAG_PREFIX = 'grp-'; | ||
|
|
||
| public function __construct(private readonly UriTagInterface $uriTag = new UriTag()) | ||
| { | ||
| } | ||
|
|
||
| #[Override] | ||
| public function __invoke(ResourceObject $ro): string | ||
| { | ||
| if (! method_exists($ro, 'onGet')) { | ||
| return self::GROUP_TAG_PREFIX . ($this->uriTag)($ro->uri); | ||
| } | ||
|
|
||
| $query = $ro->uri->query; | ||
| $baseQuery = []; | ||
| foreach ((new ReflectionMethod($ro, 'onGet'))->getParameters() as $parameter) { | ||
| if ($parameter->isDefaultValueAvailable()) { | ||
| continue; | ||
| } | ||
|
|
||
| $key = isset($query[$parameter->name]) ? $parameter->name : self::snakeName($parameter->name); | ||
| if (! isset($query[$key])) { | ||
| continue; | ||
| } | ||
|
|
||
| /** @psalm-suppress MixedAssignment */ | ||
| $baseQuery[$key] = $query[$key]; | ||
| } | ||
|
|
||
| $baseUri = clone $ro->uri; | ||
| $baseUri->query = $baseQuery; | ||
|
|
||
| return self::GROUP_TAG_PREFIX . ($this->uriTag)($baseUri); | ||
| } | ||
|
|
||
| /** The conversion BEAR.Resource applies when it binds a query to a parameter */ | ||
| private static function snakeName(string $name): string | ||
| { | ||
| return ltrim(strtolower((string) preg_replace('/[A-Z]/', '_\0', $name)), '_'); | ||
| } | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace BEAR\QueryRepository; | ||
|
|
||
| use BEAR\Resource\ResourceObject; | ||
|
|
||
| /** | ||
| * The group tag of a GET resource: its URI tag without the default-valued onGet() parameters. | ||
| * A query-variant cache entry carries it besides its own tag, and a purge of the bare URI targets it. | ||
| * | ||
| * @internal | ||
| * @see https://github.com/bearsunday/BEAR.QueryRepository/issues/255 | ||
| */ | ||
| interface BaseUriTagInterface | ||
| { | ||
| /** Without onGet(), the group tag is derived from the full URI. */ | ||
| public function __invoke(ResourceObject $ro): string; | ||
| } |
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
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.