Skip to content
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.

Commit

Permalink
Re-implement chunked_query using islice (tx @MrHamdulay).
Browse files Browse the repository at this point in the history
  • Loading branch information
hodgestar committed Jun 23, 2015
1 parent 6b83e24 commit 00f8c5e
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions go/billing/django_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
""" Billing utils that require Django. """

import json
import itertools

from django.core import serializers

Expand Down Expand Up @@ -34,13 +35,11 @@ def chunked_query(queryset, items_per_chunk=1000):
Number of objects to include in each chunk. Default 1000.
"""
with server_side_cursors(itersize=items_per_chunk):
items = []
for item in queryset.iterator():
items.append(item)
if len(items) == items_per_chunk:
yield items
items = []
if items:
iterator = queryset.iterator()
while True:
items = list(itertools.islice(iterator, items_per_chunk))
if not items:
break
yield items


Expand Down

0 comments on commit 00f8c5e

Please sign in to comment.