fix(core): scope CacheInvalidator lifetime and clear rolled-back pending entries - #2603
Open
wakqasahmed wants to merge 1 commit into
Open
fix(core): scope CacheInvalidator lifetime and clear rolled-back pending entries#2603wakqasahmed wants to merge 1 commit into
wakqasahmed wants to merge 1 commit into
Conversation
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 #2561
Summary
CacheInvalidatoris documented as request-scoped but was bound as asingleton, letting pending state outlive a request/job under Octane or long-lived workers. It's now bound with$app->scoped(...).Separately,
record()added targets to$pendingand registered anafterCommitcallback, but a rollback discarded the callback while leaving the$pendingentry in place. A later autocommit mutation, a later committed transaction, or a later transaction touching the same target could then flush an invalidation event for a change that was rolled back.The fix tracks the transaction level each pending entry was first (or most shallowly) touched at, and listens for
Illuminate\Database\Events\TransactionRolledBackper connection to drop only the entries whose shallowest touch happened inside the frame being discarded. An entry also touched by a surviving outer frame is kept (accepted over-invalidation, consistent with the class's existing reliability bias documented in its docblock).Changes
packages/core/src/LunarServiceProvider.php: bindCacheInvalidatorasscopedinstead ofsingleton.packages/core/src/Cache/CacheInvalidator.php: record the transaction level per pending entry and register a rollback listener that prunes entries whose frame was discarded.tests/core/Feature/CacheInvalidationTest.php: added regression coverage forTest plan
a root rollback does not leak into a later autocommit mutation(event dispatched 2 times instead of 1).tests/core/Feature/CacheInvalidationTest.phppass with the fix applied (ran viavendor/bin/pest, PHP 8.4, sqlite).