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

Prevent queryset caching when exporting #44

Merged

Conversation

PiDelport
Copy link
Contributor

By default, Django querysets will cache result rows as they are loaded. This can waste a large amount of memory when iteratively consuming a large queryset, like Resource.export() does. In my case, trying to export in the order of tens of thousands rows will quickly consume gigabytes of memory, before running into swap, making the export practically unusable.

Calling iterator() on the queryset fixes this behavior, and makes the large exports in question succeed without a problem.

The proposed change makes using iterator() the default behavior of Resource.export(), which should avoid the resource exhaustion problem without changing API behavior (particularly for code that overrides ModelResource.get_queryset() or ExportMixin.get_export_queryset()), and should not have any adverse effects.

(Note: This change does not affect ModelInstanceLoader.get_queryset(), which does not iterative access.)

Without this, even moderately large exports (10k rows or more) can
quickly exhaust a system's memory.
bmihelac added a commit that referenced this pull request Sep 11, 2013
Prevent queryset caching when exporting
@bmihelac bmihelac merged commit a0038e3 into django-import-export:master Sep 11, 2013
@bmihelac
Copy link
Member

Merged, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants