nanterre: build cookie for DoublonsView using score instead of created (fixes #21157)

This commit is contained in:
Benjamin Dauvergne 2018-01-12 16:05:58 +01:00 committed by Thomas NOEL
parent 7763999722
commit e15a8382a7
2 changed files with 17 additions and 4 deletions

View File

@ -54,6 +54,19 @@ def test_list_doublons(nanterre_classic_family, app):
second_data = response.json['data'][1]
third_data = response.json['data'][2]
# verify pagination respect ordering by decreasing score and increasing id
next_url = url
all_datas = []
while next_url:
response = app.get(next_url)
all_datas.extend(response.json['data'])
next_url = response.json.get('more')
if next_url:
assert response.json['data']
assert len(all_datas) == 91, 'some duplicates are missing'
l = [(-x['score'], x['id']) for x in all_datas]
assert sorted(l) == l, 'data is not properly ordered'
url = reverse('rsu-api-doublons') + '?limit=100'
response = app.get(url)
assert response.json['err'] == 0

View File

@ -1879,7 +1879,7 @@ class DoublonsView(DoublonMixin, APIView):
try:
cookie = request.GET.get('cookie', '')
cookie = cookie.split('_', 1)
since = isodate.parse_datetime(cookie[0])
score = Decimal(cookie[0])
last_id = int(cookie[1])
except:
cookie = None
@ -1919,7 +1919,7 @@ class DoublonsView(DoublonMixin, APIView):
if cookie:
qs = qs.filter(
Q(created__gt=since) | Q(created=since, id__gt=last_id)
Q(score__lt=score) | Q(score=score, id__gt=last_id)
)
qs = qs.prefetch_related(
'first__left_relations__schema', 'first__left_relations__right',
@ -1947,9 +1947,9 @@ class DoublonsView(DoublonMixin, APIView):
content.update(params)
if len(data) > limit:
since = qs[limit - 1].created.isoformat()
score = qs[limit - 1].score
max_id = qs[limit - 1].id
cookie = '%s_%s' % (since, max_id)
cookie = '%s_%s' % (score, max_id)
content['cookie'] = params['cookie'] = cookie
content['more'] = request.build_absolute_uri(reverse('rsu-api-doublons')) + '?' + urlencode(params)