Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What you're describing is a really bad combinatorics problem: for every selected category, iterate every recipe, then iterate <em>categories</em> for that recipe and then return a recipe count for that category. Even with optimized SQL you're talking about nested subselects, and logically this cannot be done in less than exponential time. (Meaning this is going to <em>really</em> hurt when you get a lot of recipes.) And with the number of possible combinations being equal to (categories)^2, caching gets more and more impractical too.</p> <p>Are you sure you have to do it this way? You're wrong about Amazon, BTW; they don't have "crossover category views" like this. They show counts of <em>search hits,</em> which is easy with a search index. Putting in "Software" in the search box isn't treating software as a category; it's treating it as a keyword.</p> <p>If no one is demanding this feature, I'd suggest simplifying it. On your category filter view, just show all the recipes that match. On each <em>recipe page</em>, you can show the sidebar list of all categories that that recipe is in, and counts for those categories if you feel like it. (Which can easily be cached as an attribute in the Categories model, and retrieved with eager loading when you bring up the recipe.)</p> <p>If you <em>do</em> have to do this for some reason -- the Powers That Be demand it under the mistaken impression that users really want to see categories they didn't filter on -- then at least do it with SQL. Nested subselects do hurt and will chew up your database's memory, but they'll be faster than doing it in Ruby. Also, there are Rails plugins that will alter the behavior of caching, so that you show the expired result on the current hit and then regenerate the cache for the <em>next</em> hit.</p> <p>But I'd seriously suggest tracking clicks and determining if anyone uses this before putting in more work.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload