2011-05-18 73 views
0

這裏的的has_many關係的領域是什麼,我現在在做:Rails的:如何緩存陣列中的

m = Merchant.find(1) 
ebay_item_id_array = [] 
active_items = m.active_items 
active_items.each { |item| 
    # Fill the array containing what items are already in the DB based on ebay item id 
    ebay_item_id_array.push(item.external_product_id) 
} 

這裏的目標是這樣,當我平eBay的API的最新產品,我可以檢查我的數據庫中是否已經有該ebay項目ID。因此,它會被跳過。問題是,當數據庫變大時,上面的這個操作效率不高。我怎樣才能將external_product_field緩存到一個數組中,我可以不用循環遍歷所有活動記錄?

回答