Commit cf5a660f7707bd487a7bd7e8e05027236ec4e623
1 parent
06a34206
Exists in
master
and in
22 other branches
ActionItem514: improved category finder to use product categorization join table
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2200 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
1 changed file
with
4 additions
and
6 deletions
Show diff stats
app/models/category_finder.rb
... | ... | @@ -59,16 +59,14 @@ class CategoryFinder |
59 | 59 | def options_for_find(klass, options={}, date_range = nil) |
60 | 60 | if defined? options[:product_category] |
61 | 61 | prod_cat = options.delete(:product_category) |
62 | - # FIXME this is SLOOOOW | |
63 | - prod_cat_ids = prod_cat.map_traversal(&:id) if prod_cat | |
64 | 62 | end |
65 | 63 | |
66 | 64 | case klass.name |
67 | 65 | when 'Comment' |
68 | 66 | {:joins => 'inner join articles_categories on articles_categories.article_id = comments.article_id', :conditions => ['articles_categories.category_id = (?)', category_id]}.merge!(options) |
69 | 67 | when 'Product' |
70 | - if prod_cat_ids | |
71 | - {:joins => 'inner join categories_profiles on products.enterprise_id = categories_profiles.profile_id', :conditions => ['categories_profiles.category_id = (?) and products.product_category_id in (?)', category_id, prod_cat_ids]}.merge!(options) | |
68 | + if prod_cat | |
69 | + {:joins => 'inner join categories_profiles on products.enterprise_id = categories_profiles.profile_id inner join product_categorizations on (product_categorizations.product_id = products.id)', :conditions => ['categories_profiles.category_id = (?) and product_categorizations.category_id = (?)', category_id, prod_cat.id]}.merge!(options) | |
72 | 70 | else |
73 | 71 | {:joins => 'inner join categories_profiles on products.enterprise_id = categories_profiles.profile_id', :conditions => ['categories_profiles.category_id = (?)', category_id]}.merge!(options) |
74 | 72 | end |
... | ... | @@ -83,8 +81,8 @@ class CategoryFinder |
83 | 81 | end |
84 | 82 | {:joins => 'inner join articles_categories on (articles_categories.article_id = articles.id)', :conditions => conditions}.merge!(options) |
85 | 83 | when 'Enterprise' |
86 | - if prod_cat_ids | |
87 | - {:joins => 'inner join categories_profiles on (categories_profiles.profile_id = profiles.id) inner join products on (products.enterprise_id = profiles.id)', :conditions => ['categories_profiles.category_id = (?) and products.product_category_id in (?)', category_id, prod_cat_ids]}.merge!(options) | |
84 | + if prod_cat | |
85 | + {:joins => 'inner join categories_profiles on (categories_profiles.profile_id = profiles.id) inner join products on (products.enterprise_id = profiles.id) inner join product_categorizations on (product_categorizations.product_id = products.id)', :conditions => ['categories_profiles.category_id = (?) and product_categorizations.category_id = (?)', category_id, prod_cat.id]}.merge!(options) | |
88 | 86 | else |
89 | 87 | {:joins => 'inner join categories_profiles on (categories_profiles.profile_id = profiles.id)', :conditions => ['categories_profiles.category_id = (?)', category_id]}.merge!(options) |
90 | 88 | end | ... | ... |