Prefetch: change the type of value prefetch accept.
It's 'auto' by default, but can be changed to 'medium' and soon another value.
This commit is contained in:
parent
a613a32628
commit
cf9b6f5904
@ -109,7 +109,7 @@ class UserSlugRelatedField(serializers.SlugRelatedField):
|
|||||||
class ChunksField(serializers.RelatedField):
|
class ChunksField(serializers.RelatedField):
|
||||||
def to_representation(self, obj):
|
def to_representation(self, obj):
|
||||||
obj = obj.chunk
|
obj = obj.chunk
|
||||||
if self.context.get('prefetch'):
|
if self.context.get('prefetch') == 'auto':
|
||||||
with open(obj.chunkFile.path, 'rb') as f:
|
with open(obj.chunkFile.path, 'rb') as f:
|
||||||
return (obj.uid, f.read())
|
return (obj.uid, f.read())
|
||||||
else:
|
else:
|
||||||
|
@ -190,7 +190,7 @@ class CollectionViewSet(BaseViewSet):
|
|||||||
|
|
||||||
def get_serializer_context(self):
|
def get_serializer_context(self):
|
||||||
context = super().get_serializer_context()
|
context = super().get_serializer_context()
|
||||||
prefetch = self.request.query_params.get('prefetch', 'true') != 'false'
|
prefetch = self.request.query_params.get('prefetch', 'auto')
|
||||||
context.update({'request': self.request, 'prefetch': prefetch})
|
context.update({'request': self.request, 'prefetch': prefetch})
|
||||||
return context
|
return context
|
||||||
|
|
||||||
@ -256,7 +256,7 @@ class CollectionItemViewSet(BaseViewSet):
|
|||||||
|
|
||||||
def get_serializer_context(self):
|
def get_serializer_context(self):
|
||||||
context = super().get_serializer_context()
|
context = super().get_serializer_context()
|
||||||
prefetch = self.request.query_params.get('prefetch', 'true') != 'false'
|
prefetch = self.request.query_params.get('prefetch', 'auto')
|
||||||
context.update({'request': self.request, 'prefetch': prefetch})
|
context.update({'request': self.request, 'prefetch': prefetch})
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user