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:
Tom Hacohen 2020-08-04 17:44:57 +03:00
parent a613a32628
commit cf9b6f5904
2 changed files with 3 additions and 3 deletions

View File

@ -109,7 +109,7 @@ class UserSlugRelatedField(serializers.SlugRelatedField):
class ChunksField(serializers.RelatedField):
def to_representation(self, obj):
obj = obj.chunk
if self.context.get('prefetch'):
if self.context.get('prefetch') == 'auto':
with open(obj.chunkFile.path, 'rb') as f:
return (obj.uid, f.read())
else:

View File

@ -190,7 +190,7 @@ class CollectionViewSet(BaseViewSet):
def get_serializer_context(self):
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})
return context
@ -256,7 +256,7 @@ class CollectionItemViewSet(BaseViewSet):
def get_serializer_context(self):
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})
return context