On Thu, Jan 26, 2012 at 8:51 PM, Linus Pettersson <
linus.petters...@gmail.com> wrote:

> This query is only to get the appropriate Categories & Subcategories.
> There are 5 Categories and 45 Subcategories.
>
> My products are imported from webshops which are using different
> categories for the same things ("tshirt", "t-shirts", "t-shirt", "short
> sleeved shirts" may all be the same). To cope with this issue I have the
> "Resellercategories" that I relate to a specific Category and Subcategory.
>
> Category/Subcategory -> Resellercategory -> Product
>
> (Resellercategories are never seen in the frontend)
>
> If I filter the products for "male" I only want to display (non-empty)
> Categories/Subcategories that have male products.
>
>
> To answer your question, there is no pagination on the Categories and
> Subcategories that I'm fetching here with this query. The query only
> returns the appropriate Categories/Subcategories. So if filtered by "male"
> it returns 3 Categories and 12 Subcategories (In my dev environment).
>

OK, I understand (small amount of categories, much more products).

If you find no other way, then the caching the "has_male_products" etc
in the Category/Subcategory may be the best remaining way.

I was also thinking, maybe it is acceptable that the set of Categories
with "male_products" etc. is only update every hour or so. That would
avoid the complexity of real-time update of that cache column. On the
other hand, an after_save on products is not _that_ difficult.

Just as a test, does your performance improve significantly if you add
a "has_male_products" column on categories and filter on that?

HTH,

Peter

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to