-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Update FlushCacheByTags to use after plugins instead of around plugins #27077
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
Update FlushCacheByTags to use after plugins instead of around plugins #27077
Conversation
Hi @navarr. Thank you for your contribution
For more details, please, review the Magento Contributor Guide documentation. |
Failed test: Failing unit test is acknowledged and fix will be pushed along with any other failures once automated testing is complete. |
@magento run Functional Tests B2B @navarr Unfortunately you need to provide DocBlock. Add them for now, and in the meantime I'm going to ask Lena about the Static Tests. @lenaorobei I thought this changed some time ago and if there are strict types - there's no need of adding doc blocks? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, you need to add the DocBlocks.
@lbajsarowicz Is that because the rule is "methods must have parameters" or b/c the rule is "tests can't fail" If its the latter, we can fix the static test thats improperly failing. If its the former, its easy enough to do. |
Moved to manual approval, as the failing test is false negative. |
@lbajsarowicz This is not ok to merge. It's fine to change the aroundSave in to an afterSave but not the delete. The delete makes operations before and after the |
@lbajsarowicz Also, the This will introduce more bugs than it fixes. I agree it should be an afterSave but the rest of the changes are 👎 . |
foreach ($this->cacheList as $cacheType) { | ||
if ($this->cacheState->isEnabled($cacheType)) { | ||
$this->cachePool->get($cacheType)->clean( | ||
\Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, | ||
\array_unique($tags) | ||
$uniqueTags = $uniqueTags ?? \array_unique($tags) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? Is this really needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously the code was performing array_unique in a loop (slow!) Caching the value locally makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, so let's do it once before and pass the variable to the for each. Write easy to read code and easy to debug code. Debugging that will be a pain in the future.
@@ -37,12 +37,6 @@ class FlushCacheByTags | |||
*/ | |||
private $tagResolver; | |||
|
|||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't remove code blocks. If you want add the long class declarations back instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-reviewing this, this was an erroneous removal as the type for $cacheList
disappears. I'll return this block.
$tags = $this->tagResolver->getTags($object); | ||
$result = $proceed($object); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tags are retrieved before deleting the Resource, not after. But we need to Purge the cache only after the delete. If the delete fails, it should rollback the transaction and not commit, hence not purge the cache. This needs to stay an around.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A rollback will throw an Exception, right? In which case the line after $proceed is not called. This same scenario occurs with the after; an exception is thrown and the after is not called.
I failed to find any instance in which the tags changed after an object was deleted. This would be the only reason to call getTags before deletion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if the entityid to crate the tag will still be available on the object once it's deleted. Need to debug and test that to make sure the tag will be created the same way once the object is deleted. The object might be a product, saleable item, category, cms page, etc... This needs to account for all these types.
@drew7721 unfortunately, only members of the maintainers team are allowed to add progress related labels to the pull request |
@drew7721 unfortunately, only members of the maintainers team are allowed to remove progress related labels to the pull request |
@magento rerun |
@navarr looks like something went wrong, I have closed and re-opened PR and check is passed now. |
@magento run all tests |
Hi @sidolov, thank you for the review.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️ All green from my side.
Hi @lbajsarowicz, thank you for the review. |
Hi @navarr, thank you for your contribution! |
Description (*)
This PR contains a few small quality of life improvements to the FlushCacheByTags class:
These original plugins were created when after plugins did not contain the arguments to the original call. Now that they do, we can move to after plugins and not affect the call stack
Calling array_unique in a loop, for the same variable isn't great. This change now caches it in a local variable.
Newer documentation standards request the exclusion of parameters and return types that are duplicative in nature. I've also updated the small descriptions to read better
Manual testing scenarios
Contribution checklist (*)
Resolved issues: