From 741b6d7c52dbe785dd3d5e94025a7c1dc23f6dff Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Tue, 13 Oct 2020 13:29:29 +0300 Subject: [PATCH] Collection removed memberships: only return removed memberships within our returned range. Before this change we were returning all of the removed memberships that happened after stoken. Though instead, we should just return the removed memberships that happened after stoken and before the new stoken we are returning. --- django_etebase/views.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/django_etebase/views.py b/django_etebase/views.py index 897bcb5..c7162dd 100644 --- a/django_etebase/views.py +++ b/django_etebase/views.py @@ -224,8 +224,13 @@ class CollectionViewSet(BaseViewSet): stoken_obj = self.get_stoken_obj(request) if stoken_obj is not None: # FIXME: honour limit? (the limit should be combined for data and this because of stoken) - remed = CollectionMemberRemoved.objects.filter(user=request.user, stoken__id__gt=stoken_obj.id) \ - .values_list('collection__main_item__uid', flat=True) + remed_qs = CollectionMemberRemoved.objects.filter(user=request.user, stoken__id__gt=stoken_obj.id) + if not ret['done']: + # We only filter by the new_stoken if we are not done. This is because if we are done, the new stoken + # can point to the most recent collection change rather than most recent removed membership. + remed_qs = remed_qs.filter(stoken__id__lte=new_stoken_obj.id) + + remed = remed_qs.values_list('collection__main_item__uid', flat=True) if len(remed) > 0: ret['removedMemberships'] = [{'uid': x} for x in remed]