Skip to content

Conversation

@kgleizes
Copy link

@kgleizes kgleizes commented Apr 25, 2025

Questions Answers
Description? Improve products count performance from sub-categories on category page (more details after).
Type improvement
BC breaks? no
Deprecations? no
Fixed ticket? No issue opened
How to test? Display category with several sub-categories and configuration mentionned above.

Description - Main objectives

When product count and sub-categories is enabled, the SQL query to retrieve the number of products per sub-category on a category page was particularly slow, and could slow down or even bring the MySQL server to its knees. This enhancement splits the process into two queries (one to retrieve the category list) and the second to output the product count. Considerable performance gains (12x to 100x faster depending number of products / categories).

More details on configuration used

First of all, we need to display one category with filters and sub-categories count enabled :
Configuration('PS_LAYERED_FULL_TREE') = 1
Configuration('PS_LAYERED_SHOW_QTIES') = 1
image

Then the category must have one model with sub categories filters enabled (layered_selection_subcategories) :
image

It's better to test without cache of blocks filters enabled and without cache to be abble to see performance before / after. You can add the constant PS_FACETED_NEWCOUNT in your defines.inc.php (or custom) to false to get previous count and compare before / after.


Explaination of diagnostic with ps profiling tool.

I noticed that the main slow query was pointing the sub-categories count.
So i tried to go deeper and check which request(s) is | are concerned.
I discover that the sub-categories product count was the main issue here and split the process in two
requests (one big as before and a very small to filter results with concerned categories).


First case - Shop with 200k+ products - 415 categories - Display of category with 5500 products

Before
image

After
image

As we can see we have following result :

  • Before - 11610 ms with 253980 results - 2195 queries
  • After - 931 ms with 3344771556 results - 2196 queries (12x faster)
    We have one more query to get the categories concerned by the filters after, and then count is filtered
    and we have the same results in output.

Second case - Shop with 5k+ products - 289 categories - Display of category with 700 products

Before
image

After
image

As we can see we have following result :

  • Before - 3664 ms with 28896 results - 2009 queries
  • After - 27.5 ms with 326163600 results - 2010 queries (133x faster)
    Same thing one more query to get categories concerned instead of add it in request for count.

To be sure that output was the same i had some json exports before after but feel free to make the
same tests and point to me any issue about this and how to reproduce.

There is some conditions remaining to allow us to test (PS_FACETED_NEWCOUNT) i can quickly remove
this when all is approved.

@ps-jarvis
Copy link

Hello @kgleizes!

This is your first pull request on ps_facetedsearch repository of the PrestaShop project.

Thank you, and welcome to this Open Source community!

@github-project-automation github-project-automation bot moved this to Ready for review in PR Dashboard Apr 25, 2025
@sneko
Copy link

sneko commented Jun 14, 2025

@Hlavtox do you know which team member could look at this PR? Thank you,

@boherm boherm requested a review from a team June 18, 2025 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready for review

Development

Successfully merging this pull request may close these issues.

4 participants