Last active
December 17, 2017 10:59
-
-
Save StevenJL/b5335cce9895a4422e08e5a309ec11aa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Selecting all users | |
User.all.each do |user| | |
notify(user) | |
end | |
# Generates this query: | |
# SELECT * FROM users; | |
# Selecting all users with `find_each` will query by batches of size | |
# determined by the :batch_size option (defaults to 1000) | |
User.all.find_each(batch_size: 5000) do |user| | |
notify(user) | |
end | |
# Generates the queries | |
# SELECT * FROM users ORDER BY users.id ASC LIMIT 5000; | |
# SELECT * FROM users WHERE users.id > 5000 ORDER BY users.id ASC LIMIT 5000; | |
# SELECT * FROM users WHERE users.id > 10000 ORDER BY users.id ASC LIMIT 5000; | |
# .... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment