Clear ORM
Search…
Cursored fetching
When resolving the query, all the models are stored in memory before being processed.
This behavior can overload the memory in case of large dataset of models. To prevent this, clear offers the methods each_with_cursorsand fetch_with_cursors :
1
User.query.each_with_cursor do |usr|
2
#...
3
end
Copied!
The block retrieved on each call can be tweaked using batch optional parameter (default: 1000 models retrieved per call) :
1
User.query.each_with_cursor(100) do |usr|
2
#...
3
end
Copied!
Copy link