Created
September 1, 2015 17:46
-
-
Save fdemmer/c7568f458d3b3f73c7c6 to your computer and use it in GitHub Desktop.
make huge queries chunk by chunk
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
def queryset_iterator(query, chunk_size=1000): | |
count = 0 | |
total = query.count() | |
while count < total: | |
for row in query[count:count + chunk_size]: | |
count += 1 | |
yield row | |
gc.collect() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment