Code:
number_of_subcategories ($category_id);
Isn't this info already stored in the category table?
Just thinking about solution...
As I remember, (Sub)Categories are only referenced by the ID of parent category.
If we have 1000 subcategories in 100 level depth, we have to do even 1000 database queries to find out the parent of each other. Correct me, if I'm wrong...
1000 queries to find just the subcategories each time, seems waste of time.
Hmmm. Well, not really, because you can fetch them from database in one step, then do the parent mapping in Perl memory, which is waaay faster. However, the idea to cache the results, would be still useful to save some CPU resource.
If you plan to use, display the subcategories info very often, seems a good idea to cache (store) the values, results.
The solution, and what you would need to store, would depend on several parameters:
- how often you need the subcat number info,
- how many times you need to use it,
- etc...
For just the number_of_subcategories() function, I would store the result numbers, especially if these are displayed, recounted often, e.g. to display on main page or category page.
Also you have to pay attention to refresh the cached items, when a related info is changed, e.g. category deleted, moved, etc...
Best regards,
Webmaster33
Paid Support from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...