Skip to content

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

Conversation

navarr
Copy link
Member

@navarr navarr commented Feb 28, 2020

Description (*)

This PR contains a few small quality of life improvements to the FlushCacheByTags class:

  1. Conversion of around plugins to after plugins.
    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
  2. Micro-optimization in cleanCacheByTags.
    Calling array_unique in a loop, for the same variable isn't great. This change now caches it in a local variable.
  3. Updating doc-blocks.
    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

  • Perform step debugging in Plugin before/after changes and compare that tags are the same during the following scenarios:
    • Product Creation
    • Production Deletion

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

Resolved issues:

  1. resolves [Issue] Update FlushCacheByTags to use after plugins instead of around plugins #29558: Update FlushCacheByTags to use after plugins instead of around plugins

@m2-assistant
Copy link

m2-assistant bot commented Feb 28, 2020

Hi @navarr. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Guide documentation.

@navarr
Copy link
Member Author

navarr commented Feb 28, 2020

Failed test: testCodeStyle is a false-positive. Code style is correct according to https://devdocs.magento.com/guides/v2.3/coding-standards/docblock-standard-general.html#functions-methods

Failing unit test is acknowledged and fix will be pushed along with any other failures once automated testing is complete.

@lbajsarowicz
Copy link
Contributor

@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?

Copy link
Contributor

@lbajsarowicz lbajsarowicz left a 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.

@navarr
Copy link
Member Author

navarr commented Feb 29, 2020

@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.

@lbajsarowicz
Copy link
Contributor

Moved to manual approval, as the failing test is false negative.

@drew7721
Copy link
Member

drew7721 commented Mar 3, 2020

@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 proceed statement. So unless that is tested and 100% sure it will not break anything nor will it leave useless data in the Redis cache then this can NOT be merged in. Also, why is this removing docs from the constructor?

@drew7721
Copy link
Member

drew7721 commented Mar 3, 2020

@lbajsarowicz Also, the clean method in the Magento\Framework\Cache\FrontendInterface is expecting an array type. What will happen when null is passed?? Seriously?!

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)
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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;

/**
Copy link
Member

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.

Copy link
Member Author

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);
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

@ghost
Copy link

ghost commented Mar 3, 2020

@drew7721 unfortunately, only members of the maintainers team are allowed to add progress related labels to the pull request

@ghost
Copy link

ghost commented Mar 3, 2020

@drew7721 unfortunately, only members of the maintainers team are allowed to remove progress related labels to the pull request

@navarr
Copy link
Member Author

navarr commented Apr 20, 2020

@magento rerun

@sidolov
Copy link
Contributor

sidolov commented Aug 26, 2020

@navarr looks like something went wrong, I have closed and re-opened PR and check is passed now.

@sidolov
Copy link
Contributor

sidolov commented Aug 26, 2020

@magento run all tests

@magento magento deleted a comment from m2-assistant bot Aug 26, 2020
@magento magento deleted a comment from m2-assistant bot Aug 26, 2020
@magento-engcom-team
Copy link
Contributor

Hi @sidolov, thank you for the review.
ENGCOM-8079 has been created to process this Pull Request
✳️ @sidolov, could you please add one of the following labels to the Pull Request?

Label Description
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests
Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests
Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests

@ihor-sviziev ihor-sviziev added the Auto-Tests: Covered All changes in Pull Request is covered by auto-tests label Aug 27, 2020
@navarr navarr requested a review from lbajsarowicz August 27, 2020 14:57
Copy link
Contributor

@lbajsarowicz lbajsarowicz left a 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.

@ghost ghost assigned lbajsarowicz Sep 19, 2020
@magento-engcom-team
Copy link
Contributor

Hi @lbajsarowicz, thank you for the review.
ENGCOM-8079 has been created to process this Pull Request

@engcom-Bravo
Copy link
Contributor

✔️ QA Passed

Manual testing scenario

  1. Configure xDebug
  2. Open the file lib/internal/Magento/Framework/App/Cache/FlushCacheByTags.php
  3. Put debug on the following lines and Start listening...
  • 73 $this->cleanCacheByTags($tags);
  • 93 $this->cleanCacheByTags($tags);
  1. Go to Magento admin and Add a new product. Click Save
  2. When xDebug stops, check the $tags array
    tags1
  3. Go to the next step, and verify that the Product has been successfully saved
  4. Delete the previously created product from Magento admin
  5. When xDebug stops, check the $tags array
    tags2
  6. Assert that the $tags after saving are the same as tags after deleting

AR: The $tags array is the same

@engcom-Bravo engcom-Bravo added the QA: Added to Regression Scope Scenario was analysed and added to Regression Testing Scope label Sep 30, 2020
@magento-engcom-team magento-engcom-team merged commit 4387884 into magento:2.4-develop Sep 30, 2020
@m2-assistant
Copy link

m2-assistant bot commented Sep 30, 2020

Hi @navarr, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@navarr navarr deleted the navarr/update-flush-cache-by-tags branch January 29, 2021 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Component: App Partner: Blue Acorn iCi Partner: Mediotype partners-contribution Pull Request is created by Magento Partner Priority: P3 May be fixed according to the position in the backlog. Progress: accept QA: Added to Regression Scope Scenario was analysed and added to Regression Testing Scope Release Line: 2.4 Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. tech-partners-contribution Technology Partner: Vertex
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[Issue] Update FlushCacheByTags to use after plugins instead of around plugins
9 participants