Skip to content
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

Fixed URL Rewrite addition/removal on product website add/remove #26999

Merged
merged 12 commits into from
Mar 28, 2020
Merged

Fixed URL Rewrite addition/removal on product website add/remove #26999

merged 12 commits into from
Mar 28, 2020

Conversation

gwharton
Copy link
Contributor

@gwharton gwharton commented Feb 25, 2020

Related Pull Requests

magento/inventory#2887

Description (*)

Moved scope of ProductToWebsiteChangeObserver to base instead of adminhtml

as this functionality has been moved to a consumer. With the observer set
to adminhtml, this observer was not being called properly on changing
the websites for a particular product in the consumer.

Corrected ProductProcessUrlRewriteSavingObserver to correctly add and remove
rewrite URLs when products are added and removed from websites using the
Product Edit Admin Page.

Corrceted ProductToWebsiteChangeObserver to correctly add and remove
rewrite URLs when products are added and removed using the Products
Grid Mass Action function.

Extended unit tests to cover both Observers.

Fixed Issues (if relevant)

  1. Closes Product URL Rewrites are not removed when product removed from website #24184: Product URL Rewrites are not removed when product removed from website
    This also fixes the issue with URL rewrites not being generated correctly using the mass action remove/add from website.

Manual testing scenarios (*)

  1. See issue

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)

@m2-assistant
Copy link

m2-assistant bot commented Feb 25, 2020

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

Moved scope of ProductToWebsiteChangeObserver to base instead of adminhtml
as this functionality has been moved to a consumer. With the observer set
to adminhtml, this observer was not being called properly on changing
the websites for a particular product in the consumer.

Corrected ProductProcessUrlRewriteSavingObserver to correctly add and remove
rewrite URLs when products are added and removed from websites using the
Product Edit Admin Page.

Corrected ProductToWebsiteChangeObserver to correctly add and remove
rewrite URLs when products are added and removed using the Products
Grid Mass Action function.

Extended unit tests to cover both Observers.

Fixed MFTF test for Product URL Rewrite generation.
@ihor-sviziev
Copy link
Contributor

@magento run Database Compare

@ihor-sviziev ihor-sviziev self-assigned this Mar 3, 2020
Copy link
Contributor

@ihor-sviziev ihor-sviziev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @gwharton,
Thank you so much for the fix! From first view your fix looks good, but url rewrites quite complex thing and usually there are no issues with single unit, but issues appears when few components works together. For such cases unit tests much less effective than integration tests, as there you’re having real objects, real db, etc and you could do some queries to db and compare with what you expect.
Could you review my comments and cover your changes with integration tests?

@gwharton
Copy link
Contributor Author

gwharton commented Mar 4, 2020

I have added a new function to the class Magento/UrlRewrite/Model/Storage/DbStorage.php.

Previously this class only provided the ability to remove a single url rewrite at a time, which lead to lengthy and nested foreach loops, with many many database transactions to process for a single operation where multiple url rewrites needed removing.

I added a new function which allows you to remove multiple url rewrite's based on arrays of entity_ids and websites_ids, allowing you to remove multiple items from multiple websites in a single operation.

Question, Would it be worth adding this new deleteEntitiesFromStores function to the UrlPersistInterface so it can sit alongside the existing deleteByData function already in that interface, and provided by DbStorage. It could be useful elsewhere.

@gwharton gwharton requested a review from ihor-sviziev March 4, 2020 14:25
@gwharton gwharton dismissed ihor-sviziev’s stale review March 4, 2020 14:26

Changes incorporated

@gwharton
Copy link
Contributor Author

gwharton commented Mar 5, 2020

Apologies for the large number of additions of <group value="urlRewrite"/> in the MFTF tests. Group allocation was inconsistent amongst UrlRewrite and CatalogUrlRewrite modules, so I took the opportunity to tag them all in a consistent group to aid running of UrlRewrite related MFTF tests.

@gwharton
Copy link
Contributor Author

gwharton commented Mar 5, 2020

Let me know if you want me to cleanup commit history and squash.

Copy link
Contributor

@ihor-sviziev ihor-sviziev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is the last iteration :)

Let's squash all changes once everything will be ready

Processed review comments.
@engcom-Echo
Copy link
Contributor

@magento run all tests

@engcom-Echo
Copy link
Contributor

Failed functional, static tests not related to the changes in this PR

@gwharton
Copy link
Contributor Author

The integration test that used to fail now passes.
The functional tests seem to pass if you re-run them enough times.
The static test failiure is nothing to do with my code.

I guess this is what you get by running the tests against the PR merged with 2.4-develop as opposed to running against the forked repo as if someone manages to commit something bad to 2.4-develop, everyones tests fail.

@ihor-sviziev
Copy link
Contributor

@engcom-Echo thank you so much!

@ihor-sviziev ihor-sviziev added the Auto-Tests: Covered All changes in Pull Request is covered by auto-tests label Mar 20, 2020
@magento-engcom-team
Copy link
Contributor

Hi @ihor-sviziev, thank you for the review.
ENGCOM-7162 has been created to process this Pull Request

@engcom-Bravo
Copy link
Contributor

✔️ QA Passed

The record for the second website disappears from the catalog_url_rewrite_product_category table after the product is unassigned
PR_26999

@engcom-Echo
Copy link
Contributor

Failed functional, static tests not related to the changes in this PR

@m2-assistant
Copy link

m2-assistant bot commented Mar 28, 2020

Hi @gwharton, 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.

@naydav
Copy link
Contributor

naydav commented Apr 6, 2020

@gwharton
Hi Graham,
We run Performance build with medium profile on 2.4-develop branch and we discovered huge degradation during Product saving in Admin panel (approximately 70% of degradation).

Server Side EE API
Create product with extensible data objects	+77.7 %	[+205 ms]
Create product	+160.8 %	[+201 ms]
Server Side EE Add to Wishlist

Server Side EE Admin Create Order
Save Shipment	+7.4 %	[+27 ms]
Add Products	+5.7 %	[+18 ms]

Server Side EE Admin Create Product
New Configurable Product Save	+85.4 %	[+698 ms]
Server Side EE Admin Customer Management

Server Side EE Admin Edit Product
Edit Simple Product Save	+13 %	[+47 ms]
Edit Configurable Product Save

Thus we had to revert changes.

We need to find a more appreciative solution or make refact of current.
Thanks

@gwharton
Copy link
Contributor Author

gwharton commented Apr 6, 2020

Understood. We did do some work on optimising it, but obviously not enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Product URL Rewrites are not removed when product removed from website
7 participants