Update two tables concurrently in Rails -
i have 2 tables: products , recommendations. first 2 million records on both tables contain same data, , differ 100k records. tables contain product ids, , need write script calls api update each products/recommendations attributes (title, price...etc). possible update attributes on both tables @ same time rather updating product models attributes, , using same script update recommendation model?
api parser:
def get_item_info(id) url_raw = uri.parse("url_id=#{id}") url = net::http.get_response(url_raw).body if url.empty? @title = "product unavailable via api" @prod_url = "url" @cover_img = "image" @price = "product unavailable via api" else begin @response1 = json.parse(url) @title = @response1["productname"] @prod_url = "#{@response1["producturl"]}" @cover_img = @response1["imagepath"].gsub("75x75.gif", "180x180.jpg") @price = @response1["currentitemprice"] rescue end end end
i getting data in real time , sending view. save images , titles db speed page load time. both products , recommendations table have same schema, , need update same columns on both tables.
you can use trigger method directly db. example, sqlite
create trigger 'triggername' after 'event' on 'tablename' when 'condition' begin update 'tablename2' set 'field' = 'value' 'condition'; end
... , not have think !!!!
Comments
Post a Comment