#10301: Refactor Serializer to support iteratation
---------------------------+------------------------------------------------
Reporter: paulegan | Owner: nobody
Status: new | Milestone:
Component: Serialization | Version: 1.0
Keywords: | Stage: Unreviewed
Has_patch: 1 |
---------------------------+------------------------------------------------
The [source:django/trunk/django/core/serializers/base.py Serializer]
interface forces the result to be fully materialised before use. This
prevents it's use for streaming responses.
Currently the closest you can come is something like the following, but
the response doesn't return until the xml document is complete:
{{{
#!python
response = HttpResponse(content_type='text/xml')
serializer = serializers.get_serializer("xml")()
serializer.serialize(queryset.iterator(), stream=response)
return response
}}}
The attached patch adds an `iterator` method to `Serializer` which yields
the serialised data in chunks. This allows the serialisation of large
query sets to be streamed to a response without using much memory:
{{{
#!python
serializer = serializers.get_serializer("xml")()
xml_iter = serializer.iterator(queryset.iterator(), chunk_size=100)
return HttpResponse(xml_iter, content_type='text/xml')
}}}
--
Ticket URL: <http://code.djangoproject.com/ticket/10301>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---