magento2: Detaching category from product causes massive product url regeneration

Preconditions

  1. Magento 2.2.5
  2. PHP 7.1

Steps to reproduce

  1. Have large catalog - I tested it against medium profile
  2. Open product form of any product
  3. Detach category, which has a lot of product (possibly some low level one, inheriting straight from root)
  4. Save product

Expected result

  1. Product saved in some fait time, max a few seconds.

Actual result

  1. Products saving about 3-4 minutes.

Actually I have debug it and this is trace to track the problem https://github.com/magento/magento2/blob/2.2/app/code/Magento/Catalog/Controller/Adminhtml/Product/Save.php:113 https://github.com/magento/magento2/blob/2.2/app/code/Magento/Catalog/Model/CategoryLinkManagement.php:assignProductToCategories() https://github.com/magento/magento2/blob/2.2/app/code/Magento/Catalog/Model/CategoryLinkRepository.php:deleteByIds() -> which triggers event catalog_category_save_after Observer https://github.com/magento/magento2/blob/2.2/app/code/Magento/CatalogUrlRewrite/Observer/CategoryProcessUrlRewriteSavingObserver.php - lines 112-3 triggers regeneration of all saved category’s products. For example for first level category of catalog having 30k products it can be 5-10k products.

Whole process is completely pointless - removing category from one product triggers massive url rewrites regeneration, which is processed during http request.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 8
  • Comments: 19 (12 by maintainers)

Most upvoted comments

@magento-engcom-team If you tell me how to fix it I could prepare pull request. I need information how te rearrange events or observers, because maybe sometimes this operation should be done (i mean regeneration of product urls). Maybe if we can do it in 2.3 we could put url regeneration on queue?

Anyway, I think we should remove all-product regeneration from category save and add that observer maybe to more accurate operations and events.

Hello @bartoszkubicki @jakoblundsted @pemann @Jakhotiya @hostep

Thank you for contribution and collaboration!

The corresponding internal ticket MAGETWO-95176 was fixed, delivered and closed by Magento team

Please see details in the next commits:

  • cf316b4
  • ee86554

@cpartica I think all question you’ve asked have been already resolved while describing the issue:

  • I think level doesn’t matter as long as this category has a lot of products (thousands to see the effect)
  • I do it on product page
  • I have it tested only on product page, but I believe it can be a problem throughut other entry points, as it is caused by massive rewrites operations, which are triggered on low-level category event (catalog_category_save_after).