Magento2: Magento rebuilds products Url when saving a category even if category path is not used for Urls.

Created on 9 Nov 2016  ·  11Comments  ·  Source: magento/magento2


All is on the title.

Preconditions


  1. Magento 2.1.1
  2. 2.

Steps to reproduce

  1. Set "Use Categories Path for Product URLs" to "No" in the configuration.
  2. Save a category
  3. Magento goes through module-catalog-url-rewrite/Observer/UrlRewriteHandler::generateProductUrlRewrites and loop over all products in the category.
  4. This makes the category saving process incredibly slow (if you have a huge bunch of products).

Expected result

  1. Magento ignores the rebuild of product Urls when saving a category.
  2. Saving a category is fast.

Actual result

  1. Saving a category is extremely long, depending on the number of products.

I precise that commits asociated to MAGETWO-58277 does not fix this in my case.

Regards.

CatalogUrlRewrite Format is valid Ready for Work bug report

All 11 comments

Hello

We have internal issue MAGETWO-59217 for this.

Hello @palamar , is there any update about this one ?

It's not assigned anymore to anyone ...

This is obviously not a bug but really nice performance improvement suggestion.

The only thing Im concerned of is how often merchants use "Use Categories Path for Product URLs" = "No" setting.

@orlangur this is clearly a bug : having something like 40.000 products on a category will lead to the impossibility of saving it. If the software is not able to work as expected, it's a bug, not performance improvement.

I have made plenty of Magento projects, and most of them does not use categories path for product URLs, especially for SEO purposes (duplicate content, avoid having too much URLs and URLs rewrites, etc...).

But that's not the question here, Magento should work properly with the both ways, and especially not rebuild Urls containing categories path if the store is not configured this way.

especially not rebuild Urls containing categories path if the store is not configured this way

Where is a bug? What is incorrect behavior? Performance is a feature, you know. The additional feature you suggested was not implemented yet.

having something like 40.000 products on a category will lead to the impossibility of saving it

No. If your environment is configured correctly to the needs of your store, impossibility will never occur. I saw mentioned here in another ticket that reasonable amount of products per category is considered to be 10.000.

@orlangur you must be obviously trolling.

We have a dedicated option in the back-office set to "No". Magento runs a process which should be ran only when this option is set to "Yes".

How do you call this ? a feature ? nope. It's a bug. And this is clear that its a bug because Magento itself acknowledge it...

And when "performance" issue leads to a normal software function being impossible to behave correctly (saving a category), this is clearly a bug.

I will not spend anymore time answering you on this issue, because you are clearly showing bad faith. I will just wait for Magento and @palamar answer here.

Regards,

Performance is a feature, you know.

Are you serious? It's so frustrating working with Magento, and I start to understand why...

If a task takes 20 seconds to complete or executes unnecessary calls, it has a bug. Period.

We have a dedicated option in the back-office set to "No". Magento runs a process which should be ran only when this option is set to "Yes".

Not that simple.

When you hit Save for Product or Category and you changed some field affecting URLs, all existed urlrewrites for all affected entities are regenerated (i.e. dropped and then saved). So, there are a lot of corner cases when you deal with deep child categories, when you move categories and such.

On top of this mechanism you can implement additional optimizations according to your observations. The one which you suggested allows to decrease amount of generated urlrewrites drastically for one particular configurations case by reducing the "all affected entities".

Now let's switch back to what I'm trying to say. I'm not trying to say that category saving should work that slow and I'm not trying to say that it's impossible to fix this particular case quickly enough.


What I'm trying to say in fact is that in my opinion any software product need to have clear set of requirements and implementation fulfilling these requirements.

When new urlrewrites feature was designed some set of requirements was considered and then fulfilled with initial implementation.

Currently we see that real world challenges arisen which go beyond initial set of requirements. According to my understanding as a consequence set of requirements needs to be revised according to merchant needs and only after that the plan on fixing problem should go.

Suggested bugfix will solve the problem with "Use Categories Path for Product URLs" to "No" but what if you want to set "Yes"? Should category saving still work that slow for another case? How fast the feature should work for Yes/No, for 1000/10.000/40.000 products in category?

So, what I'm actually against are symptomatic fixes without understanding the whole picture.

Bug = situation when some implementation does not correspond to existing requirement and it needs to be fixed without changing set of requirements;
Feature = situation when we introduce additional, nonexistent before, requirement and fulfill it with implementation;

Hope it makes sense to you.

Oh, and to clarify which implementation approach I consider as most promising.

I believe the root cause is "drop everything and then insert everything back" approach. I think there should be smarter mechanism of persisting urlrewrites so that only necessary table rows are affected. Doctrine can do it out-of-the-box, even if it is not used in Magento yet I don't see a reason why Magento ORM cannot do the same.

Obviously, with such approach embodied into life your particular case will work like a charm as there are no urlrewrites affected with such combination of settings. Note, that you will also not need any additional code for "bugfix" and you can safely remove any similar bugfixes for other cases introduced before.

Hi @palamar or anyone else from Magento. Is anyone looking at resolving this issue? Classify this as you see fit, but it impedes in being able to work with categories when you have a large number of products and also heavily pollutes the URL rewrites tables with un-necessary data that is absolutely pointless when magento is configured not to use category paths in the product URLs. Pls advise when it may be fixed.

@romainruaud, thank you for your report.
The issue is already fixed in 2.2.0

Was this page helpful?
0 / 5 - 0 ratings