user#assign_closeted_to_items! now assigns when there are duplicates

This commit is contained in:
Emi Matchu 2011-08-03 10:18:03 -04:00
parent 513711bf60
commit 63bc0067c0

View file

@ -52,9 +52,13 @@ class User < ActiveRecord::Base
# N^2 searching the items list for items that match the given IDs or vice
# versa, and everything stays a lovely O(n)
items_by_id = {}
items.each { |item| items_by_id[item.id] = item }
items.each do |item|
items_by_id[item.id] ||= []
items_by_id[item.id] << item
end
closet_hangers.where(:item_id => items_by_id.keys).each do |hanger|
item = items_by_id[hanger.item_id]
items = items_by_id[hanger.item_id]
items.each do |item|
if hanger.owned?
item.owned = true
else
@ -62,6 +66,7 @@ class User < ActiveRecord::Base
end
end
end
end
def closet_hangers_groups_visible_to(user)
return [true, false] if user == self