Filter by stoken: fix the done implementation for more functions
The done implementation wasn't great because it would indicate we are not done even when we are when the last chunk returned is exactly the size of limit.
This commit is contained in:
@@ -288,13 +288,16 @@ class CollectionItemViewSet(BaseViewSet):
|
|||||||
iterator = get_object_or_404(queryset, uid=iterator)
|
iterator = get_object_or_404(queryset, uid=iterator)
|
||||||
queryset = queryset.filter(id__lt=iterator.id)
|
queryset = queryset.filter(id__lt=iterator.id)
|
||||||
|
|
||||||
queryset = queryset[:limit]
|
result = list(queryset[:limit + 1])
|
||||||
serializer = CollectionItemRevisionSerializer(queryset, context=self.get_serializer_context(), many=True)
|
if len(result) < limit + 1:
|
||||||
|
done = True
|
||||||
|
else:
|
||||||
|
done = False
|
||||||
|
result = result[:-1]
|
||||||
|
|
||||||
# This is not the most efficient way of implementing this, but it's good enough
|
serializer = CollectionItemRevisionSerializer(result, context=self.get_serializer_context(), many=True)
|
||||||
done = len(queryset) < limit
|
|
||||||
|
|
||||||
last_item = len(queryset) > 0 and serializer.data[-1]
|
last_item = len(result) > 0 and serializer.data[-1]
|
||||||
|
|
||||||
ret = {
|
ret = {
|
||||||
'data': serializer.data,
|
'data': serializer.data,
|
||||||
@@ -510,13 +513,16 @@ class InvitationBaseViewSet(BaseViewSet):
|
|||||||
iterator = get_object_or_404(queryset, uid=iterator)
|
iterator = get_object_or_404(queryset, uid=iterator)
|
||||||
queryset = queryset.filter(id__gt=iterator.id)
|
queryset = queryset.filter(id__gt=iterator.id)
|
||||||
|
|
||||||
queryset = queryset[:limit]
|
result = list(queryset[:limit + 1])
|
||||||
serializer = self.get_serializer(queryset, many=True)
|
if len(result) < limit + 1:
|
||||||
|
done = True
|
||||||
|
else:
|
||||||
|
done = False
|
||||||
|
result = result[:-1]
|
||||||
|
|
||||||
# This is not the most efficient way of implementing this, but it's good enough
|
serializer = self.get_serializer(result, many=True)
|
||||||
done = len(queryset) < limit
|
|
||||||
|
|
||||||
last_item = len(queryset) > 0 and serializer.data[-1]
|
last_item = len(result) > 0 and serializer.data[-1]
|
||||||
|
|
||||||
ret = {
|
ret = {
|
||||||
'data': serializer.data,
|
'data': serializer.data,
|
||||||
|
|||||||
Reference in New Issue
Block a user