Does find_in_batches uses different DB connection for each batch?

3091 views activerecord
2

I'm thinking of using sleep within find_in_batches to wait before processing the batch. Is it a right way to do? I'm wondering, does this block the DB connection? Or it just uses different DB connections for each batch in which case I can use the sleep without worrying too much?

answered question

1 Answer

5

find_in_batches does not reserve a connection, it simply picks a connection from ActiveRecord's connection pool each time a new batch is yielded. You can use sleep safely.

posted this

Have an answer?

JD

Please login first before posting an answer.