fix(core): queue-safe catalog invalidation events (#2562) - #2600
Open
wakqasahmed wants to merge 1 commit into
Open
fix(core): queue-safe catalog invalidation events (#2562)#2600wakqasahmed 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 #2562
Problem
ProductInvalidated,CollectionInvalidated,BrandInvalidated, andProductOptionInvalidateduseIlluminate\Queue\SerializesModelson their model property. That trait's__unserializerestores the model by re-querying the database withfirstOrFail(). For aDeletedinvalidation, the row is already gone by the time a queued listener processes the job, so deserialization throwsModelNotFoundExceptionbefore the listener can readmorphType(),cacheKey(),cacheTags(), orreason()— the scalar identity the contract promises is captured at record time specifically so it survives a deleted row.Fix
Added
Lunar\Core\Concerns\SerializesInvalidatedModel, a queue-safe drop-in forSerializesModelson these four events. Instead of aModelIdentifierthat gets re-queried on unserialize, it captures the model's raw attributes at serialize time and rehydrates an in-memory instance vianewFromBuilder()on unserialize — no query, so it can't fail even when the row no longer exists.cacheModel()still returns a real, fully-attributedModelinstance; the public contract (CacheInvalidationEvent) is unchanged.This is narrower than the additive scalar-only event / DTO the issue floated as an option: no new public surface, no change to the documented queued contract, and the model-bearing events become safe to queue as-is.
Test plan
tests/core/Feature/CacheInvalidationTest.phpcoverage that constructs each of the four invalidation events, hard-deletes the underlying row, round-trips the event through PHP's realserialize()/unserialize()(the same mechanism a queued job uses), and asserts the restored event's scalar identity (cacheKey(),cacheTags(),morphType(),reason()) andcacheModel()are readable without hitting the database.tests/core/Feature/CacheInvalidationTest.phpsuite (24 tests, 41 assertions) — all green, including the pre-existing coverage.