Tuesday, 18 June 2013

Rails update



Cup.update_all({:broken_handle => true}, {:broken_handle => false})



The first argument are the attributes to update and the second is the filter conditions for the query.


Batches in Rails



a.  find_each
b. find_in_batches

 1.  It's use is intended for batch processing of large amounts of records that wouldn't fit in memory all at once.

2. If we just want to loop over less than 1000 records(which is default batch size), it's good to use the find methods.

3. We can control the starting point for the batch processing by supplying the :start option. This is useful if we want multiple workers dealing with the same processing queue. Say for example if we want worker_1 to handle records b/w 0 to 5000 and worker_2 from 5000 to 10000 by setting :start option on that worker.



No comments:

Post a Comment