考虑我有 15 个类别和 6 个子类别,并且我有表项,其中我有一组记录,我必须以下列方式获取
category 1 ---> level 1 ---> 3 items with maximum price
category 1 ---> level 2 ---> 3 items with maximum price
...
...
...
category 15 ---> level 6 ---> 3 items with maximum price
和
@categories.each do |value|
@sub-categories.each do |value1|
array = Item.find(:all, :conditions => ["customer_id IN (?) AND category_id = ? AND sub-category_id = ?", @customer, value.id, value1.id], :order => 'price DESC', :limit => 3)
array.each do |value2|
@max_price_item_of_each_customer << value2
end
end
end
但这会花费很多时间,因为它会迭代。那么我怎样才能以这样的方式改变这一点,可以减少时间呢?任何帮助表示赞赏。