From cf9b6f5904c22c7a03e719d914b308da22261371 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Tue, 4 Aug 2020 17:44:57 +0300 Subject: [PATCH] Prefetch: change the type of value prefetch accept. It's 'auto' by default, but can be changed to 'medium' and soon another value. --- django_etebase/serializers.py | 2 +- django_etebase/views.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/django_etebase/serializers.py b/django_etebase/serializers.py index 8cfddad..40f6068 100644 --- a/django_etebase/serializers.py +++ b/django_etebase/serializers.py @@ -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: diff --git a/django_etebase/views.py b/django_etebase/views.py index 95031e3..9d76d08 100644 --- a/django_etebase/views.py +++ b/django_etebase/views.py @@ -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