Answer the question
In order to leave comments, you need to log in
Large tree structure element counters?
There is a nested tree structure of 70,000 elements - a tree of product categories. The task is to display those categories that have at least one product, and display the number of products for each category.
The question is how best to implement it. There was an attempt to update the counter of each category on mysql triggers when changing / adding / deleting a product, but when loading a large amount of goods, such a system works extremely unstable, or rather for a long time. Has anyone faced such issues?
Answer the question
In order to leave comments, you need to log in
Also, if we are talking about an online store, you can cache the number of products in each category, or recalculate and save the cron once every 5 minutes (via the SELECT COUNT (*) GROUP BY category_id query), but I like the L0NGMAN approach more.
> There was an attempt to update the counter of each category on mysql-triggers when changing / adding / deleting goods, but when loading a large amount of goods, such a system does not work extremely stable, or rather for a long time.
So you have bad code, you need to optimize it, maybe do the same without triggers.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question