mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-06-11 17:13:21 +03:00
in order to solve the memory leak at #5146
Large encoded string take a very long time to to release from memory, but if we just pass the stream directly into json.load we get much better memory performance.
This commit is contained in:
parent
1ca5a9d042
commit
3a2ad8e68c
|
@ -22,6 +22,7 @@ from django.utils.six.moves.urllib import parse as urlparse
|
||||||
|
|
||||||
from rest_framework import renderers
|
from rest_framework import renderers
|
||||||
from rest_framework.exceptions import ParseError
|
from rest_framework.exceptions import ParseError
|
||||||
|
import codecs
|
||||||
|
|
||||||
|
|
||||||
class DataAndFiles(object):
|
class DataAndFiles(object):
|
||||||
|
@ -61,8 +62,8 @@ class JSONParser(BaseParser):
|
||||||
encoding = parser_context.get('encoding', settings.DEFAULT_CHARSET)
|
encoding = parser_context.get('encoding', settings.DEFAULT_CHARSET)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data = stream.read().decode(encoding)
|
decoded_stream = codecs.decode(stream, encoding)
|
||||||
return json.loads(data)
|
return json.load(decoded_stream)
|
||||||
except ValueError as exc:
|
except ValueError as exc:
|
||||||
raise ParseError('JSON parse error - %s' % six.text_type(exc))
|
raise ParseError('JSON parse error - %s' % six.text_type(exc))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user