ruby on rails - How do I update User object at scale? -


my ruby on rails application has 100,000,000 users. have column on model called 'data' json field contains small json object backup saving new field.

if had 1,000 users run:

users = user.all users.each |user|     user.data_backup = user.data     user.save end 

and save existing data new column. however, potentially take forever many users. what's proper and/or efficient way update field on model @ scale when have 100,000,000+ users?

for large number of records, try use find_in_batchs method

user.find_in_batches(batch_size: 1000) |users|   users.each |user|     user.data_backup = user.data     user.save   end end 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -