Can someone recommend a good data structure/way for this use case? I'm using Ruby/Rails with MySQL.
I have a product feed with tens of thousands of products (with price, url, product_code, etc). I access the feed once a day and want to store the product info into a quickly accessible hash that persists in the database once the program stops running.
Should this (potentially very large) hash be its own class, or perhaps a serialized property of Product class?
My pseudocode:
Saving product feed data into hash and storing in database:
all_products_hash = Hash.new
product_feed = get_feed_api()
product_feed.for_each |product| do
updated_product = Product.new(product.url, product.code, product.price)
all_products_hash[product.url] = updated_product
end
all_products_hash.save
Retrieving hash content (not sure how to retrieve hash from database):
a_product = all_products_hash.get['url']
The key to the hash is the product.url. Am I initializing the hash correctly? Many thanks for any advice!