Permalink
Browse files

Improving retrieving of products to be resistant to debris in the ses…

…sion (like manual calls of metal with wrong ids)
  • Loading branch information...
romul committed Oct 27, 2009
1 parent 0a95961 commit 1bb7d48f60d0435307c12e1028dd0f9847d82000
Showing with 7 additions and 3 deletions.
  1. +7 −3 recently_viewed_extension.rb
@@ -23,9 +23,13 @@ def get_recently_viewed_products_ids
def self.find_by_array_of_ids(ids)
ids.map! { |id| id.to_i }
products = Product.find(:all, :conditions => ["id IN (?)", ids])
- sorted_products = Array.new(products.size)
- products.map { |p| sorted_products[ids.index(p.id)] = p }
- sorted_products
+ sorted_products = Array.new(ids.size)
+ products.each do |p|
+ idx = ids.index(p.id)
+ sorted_products[idx] = p unless idx.nil?
+ end
+ sorted_products.delete(nil)
+ sorted_products
end
end
end

0 comments on commit 1bb7d48

Please sign in to comment.