Iterating over a large QuerySet doesn't seem to be a viable option in Django 2.0 anymore. I've tried to speed it up using Django's own Paginator.
def read_from_db_4():
paginator = Paginator(DataSet.objects.filter(status_id=1).order_by('id'), 1000)
l = []
print("{} iterations!".format(paginator.num_pages))
for page in range(1, paginator.num_pages+1):
l = l + list(paginator.page(page).object_list)
print("{}, next page...".format(page))
return l
This little function is reasonably quick but will stop on the very last page.
I can also not get to the length of this page:
len(paginator.page(LASTPAGE).object_list)
this will just hang forever. I can get the length of all other pages previously.
What's the reason for this odd behaviour?