Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround QuerySet.iterator() not handling large datasets #267

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions mssql/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,15 @@ def sqlserver_sha512(self, compiler, connection, **extra_context):
)


def sqlserver_iterator(queryset, chunk_size=2000):
steps = int(queryset.count() / chunk_size + 1)
step = 0
while step < steps:
for obj in queryset[chunk_size * step : (step + 1) * chunk_size]:
yield obj
step += 1


# `as_microsoft` called by django.db.models.sql.compiler based on connection.vendor
ATan2.as_microsoft = sqlserver_atan2
# Need copy of old In.split_parameter_list_as_sql for other backends to call
Expand Down Expand Up @@ -475,3 +484,4 @@ def sqlserver_sha512(self, compiler, connection, **extra_context):

OrderBy.as_microsoft = sqlserver_orderby
QuerySet.bulk_update = bulk_update_with_default
QuerySet.iterator = sqlserver_iterator