ruby on rails - Calculating item counters for a set of selected categories -


There are many classification criteria for recipes in our Ruby on railway projects, such as cook method, opportunity etc. Each recipe is one or several of these categories when one starts browsing for recipes, then it can reduce a set of specific categories. So we need to calculate the number of recipes in all categories accessible from this set ("accessible" means that there are dishes in the category which are of the selected categories). This is similar to how Amazon search works: Someone enters the 'software' and the menu on the left is called "books (200)", "movies (300)" etc., so that users can click on these links Can go deeper.

We have implemented it now:

  1. create a set of selected categories from the URL;
  2. Make a query that matches the category IDs from all the recipes that are currently in selected criteria;
  3. Create an index that maps all the category IDs for the count of recipes, and present only those who have zero-zero counter;
  4. Store this index in Memcach for 24 hours, so we only count once per day for a particular page.

My concern is that if there is a cash missile, the index can take a lot of work. Perhaps you have a suggestion to solve this problem or improve the current solution?

What you're describing is a really bad connector problem: For every selected category, Repeat every recipe, then repeat categories for that recipe and then return the prescription count for that category. Even with the optimized SQL you are talking about nested practices, and logically it can not be done in less than the exponential time. (This means that when you get a lot of recipes, then actually is hurt.) And if the number of possible combinations (categories) is equal to ^ 2, caching is more and more impractical it happens.

Are you sure you want to do this? You are wrong about Amazon, BTW; They do not do such "ideas of the crossover category", they calculate search hits, which is easy with a search index. By putting "software" in the search box, the software is not considered as a category; It is treating as a keyword.

If no one is asking for this facility, then I suggest making it simpler. On your category filter view, just show all the recipes that match. On each recipe page , you can show the sidebar list of all the categories that are in the recipe, and if you like it, then it is counted for those categories (which can be easily counted in the Cateband model Cache can be done as an attribute, and curious loading is done when you take the recipe.)

If you do do do something for the cause - Under this misconception of those rights, there is a demand that the user Nets really want to see those categories that they do not filter - then at least with SQL nested subtitles hurt and will chew your database memory, but doing so in Ruby will work faster. In addition, there are Rail plugins that will change the caching behavior, so that you can show results ending on the current hit and then rebuild the cache for next hit.

But

I strongly recommend tracking clicks and determine if anyone uses it.

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -