ruby on rails - Overwriting data to the model -


i using reading table oracle , writing data model using cronjob everymidnight me caching data , enhance speed. using create method writing data in model create new entries , duplicate data in model everytime. there method in model update data or overwrite?

  model.each |model|       p = model.create model.attributes       p.save     end 

why want save models? won't caching. should instead profile application , implement caching techniques memcached.

but anyways here's code read table:

model.each {|model| model.new model.attributes } 

update according clarification: copying 1 db without duplication done (given model1 accesses source db , model2 access destination db):

model1.each |model1|   model2 = model2.find_or_initialize_by_id model1.id, model1.attributes   model2.save! } 

this won't handle deletions, however. may still want memcached , maybe database sharding. may worth thinking master/slave replication on database level "slow" database master (all database writes go this) , slave "fast" database (all read go this). web applications read bound, in case. rails has support this, see newrelic's scaling rails screencast series scaling databases.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -